欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php关于数组的有关问题

程序员文章站 2022-03-29 14:18:12
...
php关于数组的问题

array (size=3)
0 =>
array (size=3)
0 =>
array (size=3)
'welfareName' => string '包吃住' (length=9)
'welfareIco' => string 'url_1' (length=5)
'xyId' => int 1
1 =>
array (size=3)
'welfareName' => string '头等舱' (length=9)
'welfareIco' => string 'url_2' (length=5)
'xyId' => int 1
2 =>
array (size=3)
'welfareName' => string '有车' (length=6)
'welfareIco' => string 'url_4' (length=5)
'xyId' => int 1
1 =>
array (size=2)
0 =>
array (size=3)
'welfareName' => string '头等舱' (length=9)
'welfareIco' => string 'url_2' (length=5)
'xyId' => int 2
1 =>
array (size=3)
'welfareName' => string '买买买' (length=9)
'welfareIco' => string 'url_3' (length=5)
'xyId' => int 2

---------------------------------------------------------
array (size=3)
0 =>
array (size=11)
'xyId' => int 1
'xyLocation' => string '首尔' (length=6)
'commentNum' => int 3
'visitorNum' => int 1
1 =>
array (size=11)
'xyId' => int 2
'xyLocation' => string '东京' (length=6)
'commentNum' => int 0
'visitorNum' => int 1
--------------------------------------------------------------------------------
array (size=3)
0 =>
array (size=11)
'xyId' => int 1
'xyLocation' => string '首尔' (length=6)
'commentNum' => int 3
'visitorNum' => int 1
'welfare' =>
array (size=3)
0 =>
array (size=3)
'welfareName' => string '包吃住' (length=9)
'welfareIco' => string 'url_1' (length=5)
'xyId' => int 1
1 =>
array (size=3)
'welfareName' => string '头等舱' (length=9)
'welfareIco' => string 'url_2' (length=5)
'xyId' => int 1
2 =>
array (size=3)
'welfareName' => string '有车' (length=6)
'welfareIco' => string 'url_4' (length=5)
'xyId' => int 1

1 =>
array (size=11)
'xyId' => int 2
'xyLocation' => string '东京' (length=6)
'commentNum' => int 0
'visitorNum' => int 1
'welfare' =>
array (size=2)
0 =>
array (size=3)
'welfareName' => string '头等舱' (length=9)
'welfareIco' => string 'url_2' (length=5)
'xyId' => int 2
1 =>
array (size=3)
'welfareName' => string '买买买' (length=9)
'welfareIco' => string 'url_3' (length=5)
'xyId' => int 2

------解决思路----------------------
for($i=0; $i  $数组3[$i] = $数组2;
$数组3[$i]['welfare'] = @$数组1[$i];
}

------解决思路----------------------

$arr1=array(
array (
array (
'welfareName' => '包吃住',
'welfareIco' => 'url_1',
'xyId' => 1
),
array (
'welfareName' => '头等舱',
'welfareIco' => 'url_2',
'xyId' =>1
),
array (
'welfareName' =>'有车',
'welfareIco' => 'url_4',
'xyId' =>1
)
),
array (
array (
'welfareName' => '头等舱',
'welfareIco' => 'url_2',
'xyId' =>2
),
array (
'welfareName' => '买买买',
'welfareIco' => 'url_3',
'xyId' =>2
)
)
);
$arr2=array(
array (
'xyId' => 1,
'xyLocation' => '首尔',
'commentNum' =>3,
'visitorNum' =>1,
),
array (
'xyId' => 2,
'xyLocation' => '东京',
'commentNum' => 0,
'visitorNum' => 1,
)
);
foreach($arr1 as $k=>$v){
$new[$v[0]['xyId']]=$v;
}
foreach($arr2 as $k=>$v){
$arr2[$k]['welfare']=$new[$v['xyId']];
}
php关于数组的有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频