我有两个数组:
$array1 = array("A","One","C","Z");
$array2 = array("B","K","2","5");
是否有一些内置的PHP方法来获取最终数组(我不知道怎么说,可能是1-1对应添加)备用键相互追加
$final_array = array("A","B","One","K","C","2","Z","5");
如果我使用array_merge,我得到:
$final_array = array("A","One","C","Z","B","K","2","5")
但这正是array_merge的作用。除了循环之外还有其他解决方法吗?
答案 0 :(得分:2)
试试这个:
$array1 = array(1,3,5,7);
$array2 = array(2,4,6,8);
$final_array = array_merge($array1,$array2);
sort($final_array);
print_r($final_array);
希望这会有所帮助。使用sort
函数对数组进行排序。