I m trying to create a third array of numbers by showing the 4 first elements from first array and 1 first elements from the second array and so on.
Example:
A1 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21, 22, 23, 24, 25 }
A2 {11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }
And the result should be:
A3 { 1, 2, 3, 4, 11, 5, 6, 7, 8, 12, 9, 10, 21, 22, 13, ... }
└───┬────┘ ↑↑ └───┬────┘ ↑↑ └─────┬─────┘ ↑↑
A1 A2 A1 A2 A1 A2
Right now I tried this code, but it doesn't show all elements from the second array.
<?php
$array = array(1, 2, 3, 4, 5,6,7,8,9,10);
$array2 = array(11, 12, 13, 14, 15 ,16,17,18,19,20);
$temp = 0;
foreach ($array as $key => $item)
{
echo $item;
if(($key+1) % 4 == '0')
{
echo $array2[$temp];
$temp++;
}
}
?>