如何根据值合并两个多维数组? [英] How to merge two muti dimensional array according to the values?
本文介绍了如何根据值合并两个多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个这样的数组
array (
[0]=>array(
[0]=>10,
[1]=>Some Name..
),
[1]=>array(
[0]=>11,
[1]=>Some Name..
),
[2]=>array(
[0]=>13,
[1]=>Some Name..
)
)
另一个这样的数组
array (
[0]=>array(
[0]=>13,
[1]=>Viewed
)
)
如何在不使用任何循环的情况下合并以上两个数组?有任何php功能可用于此吗?我需要这种输出
How can I merge above two arrays without using any looping? Any php functionality is available for this? I need this kind of an out put
array (
[0]=>array(
[0]=>10,
[1]=>Some Name..
),
[1]=>array(
[0]=>11,
[1]=>Some Name..
), [2]=>array(
[0]=>13,
[1]=>Some Name..
[2]=Viewed
)
)
推荐答案
You can use the PHP function array_merge_recursive. See the example:
<?php
$ar1 = array("color" => array("favorite" => "red"), 5);
$ar2 = array(10, "color" => array("favorite" => "green", "blue"));
$result = array_merge_recursive($ar1, $ar2);
print_r($result);
?>
这篇关于如何根据值合并两个多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文