Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Last active May 12, 2017 09:44
Show Gist options
  • Save Cvetomird91/55ccb6e06b664847c5989486020af20a to your computer and use it in GitHub Desktop.
Save Cvetomird91/55ccb6e06b664847c5989486020af20a to your computer and use it in GitHub Desktop.
<?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