php关于数组的问题

Dukerm 2015-05-22 03:11:06

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
...全文
160 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
果酱很好吃 2015-05-23
  • 打赏
  • 举报
回复
多练多写,就深刻了
Dukerm 2015-05-23
  • 打赏
  • 举报
回复
引用 4 楼 jam00 的回复:

$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']];
}
这个解决了,我对数组理解不够深刻
Dukerm 2015-05-23
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
for($i=0; $i<count($数组2); $i++) {
  $数组3[$i] = $数组2;
  $数组3[$i]['welfare'] = @$数组1[$i];
}
版主的这个,也能实现,但是会多出好多多余数组,同样感谢
Dukerm 2015-05-23
  • 打赏
  • 举报
回复
引用 6 楼 jam00 的回复:
多练多写,就深刻了
受教了
果酱很好吃 2015-05-22
  • 打赏
  • 举报
回复

$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']];
}
xuzuning 2015-05-22
  • 打赏
  • 举报
回复
for($i=0; $i<count($数组2); $i++) {
  $数组3[$i] = $数组2;
  $数组3[$i]['welfare'] = @$数组1[$i];
}
Dukerm 2015-05-22
  • 打赏
  • 举报
回复
求解决啊~~~~~~
Dukerm 2015-05-22
  • 打赏
  • 举报
回复
相当于把第一个数组作为第二个数组的一个键对应的值,请问该怎么实现实现第三个数组啊

21,879

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧