Last active
May 12, 2017 09:44
-
-
Save Cvetomird91/55ccb6e06b664847c5989486020af20a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array1 = array(1, 2, 3, 4, 5); | |
$array2 = array(6,7,8,9); | |
$arrays_total_length = count($array1) + count($array2); | |
$index1 = 0; | |
$index2 = 0; | |
$output_array = array(); | |
for ($i = 0; $i < $arrays_total_length; $i++) { | |
if ($i % 2 == 0) { | |
array_push($output_array, $array1[$index1]); | |
$index1++; | |
} | |
if ($i % 2 != 0) { | |
array_push($output_array, $array2[$index2]); | |
$index2++; | |
} | |
} | |
print_r($output_array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment