P粉1557104252023-08-09 13:10:17
Here is one way to do this (assuming both arrays are of the same size):
function merge($a1, $a2) { $a3 = []; $len = count($a1); for($i=0;$i<$len;$i++) { $a3 []= $a1[$i]; $a3 []= $a2[$i]; } return $a3; } $a1 = [1, 2, 3]; $a2 = [4, 5, 6]; $a3 = merge($a1, $a2); var_dump($a3);