我有两个这样的数组:
$array1 = [
[10, 'Some Name..'],
[11, 'Some Name..'],
[13, 'Some Name..'],
];
$array2 = [
[13, 'Viewed']
];
如何在不循环的情况下合并这两个数组?是否有任何可用的 php 功能?我需要这种输出:
[
[10, 'Some Name..'],
[11, 'Some Name..'],
[13, 'Some Name..', 'Viewed']
]
最佳答案
可以使用PHP函数 array_merge_recursive 强>。 看例子:
<?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);
?>
关于php - 根据第一列值合并两个索引数组的索引数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8879767/