另外合并两个数组

Hak*_*kim 2 php arrays

我要的是一个efficient(不循环)方式,该方式合并阵列first element of the resulting arrayfirst element of the first array,the second element of the resulting arraythe second element of the second array(或者)...等

例:

$arr1 = array(1, 3, 5);
$arr2 = array(2, 4, 6);

$resultingArray = array(1, 2, 3, 4, 5, 6);
Run Code Online (Sandbox Code Playgroud)

Dev*_*er0 7

假设两个阵列具有相同的长度.

$arr1 = array(1, 3, 5);
$arr2 = array(2, 4, 6);

$new = array();
for ($i=0; $i<count($arr1); $i++) {
   $new[] = $arr1[$i];
   $new[] = $arr2[$i];
}
var_dump($new);
Run Code Online (Sandbox Code Playgroud)