【发布时间】:2017-05-19 09:33:16
【问题描述】:
我有两个数组
$array1[0]=array("account"=>002,"prin"=>100,"intr"=>50,"date"=>"2017-05-13");
$array1[1]=array("account"=>002,"prin"=>100,"intr"=>50,"date"=>"2017-05-20");
$array2[0]=array("account"=>002,"others"=>30,"date"=>"2017-05-13");
$array2[0]=array("account"=>002,"others"=>20,"date"=>"2017-05-13");
$array2[1]=array("account"=>002,"others"=>30,"date"=>"2017-05-20");
$array2[2]=array("account"=>002,"others"=>20,"date"=>"2017-05-20");
我想像这样将这两个数组组合成一个
$array3[0]=array("account"=>002,"prin"=>100,"intr"=>50,"date"=>"2017-05-13","others"=>30);
$array3[1]=array("account"=>002,"prin"=>'',"intr"=>'',"date"=>"2017-05-13","others"=>20);
$array3[3]=array("account"=>002,"prin"=>100,"intr"=>50,"date"=>"2017-05-20","others"=>30);
$array3[4]=array("account"=>002,"prin"=>'',"intr"=>'',"date"=>"2017-05-20","others"=>20);
我正在尝试 array_merge,但它没有给我想要的结果。 任何输入都会有很大帮助。谢谢
【问题讨论】:
-
使用php的array_merge()函数
-
你试过
array_merge_recursive()php.net/manual/en/function.array-merge-recursive.php吗? -
array2怎么会有两个0索引
-
@SaurabhParekh 他已经提到他遇到了 array_merge 的问题,那你为什么还要提到同样的问题?
-
我不清楚您要合并哪些数组。你可以再详细一点吗?是基于“account”和“date”的值吗?
标签: php associative-array