h4k1m - 1 year ago 149

PHP Question

What I want is an

`efficient`

`first element of the resulting array`

`first element of the first array`

`the second element of the resulting array`

`the second element of the second array`

Example:

`$arr1 = array(1, 3, 5);`

$arr2 = array(2, 4, 6);

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

Answer Source

assuming both arrays have the same length.

```
$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);
```