I created two arrays. First the arrays show the elements with no order whatsoever. So, I have to sort them first by alphabetical order and lowest-to-highest. Once in order, the two arrays that need to be combined in such way that each element from each array are combined according to their index number.
My goal: a0 b1 c2 d3 e4 f5 g6
What I’m getting: abcdefg0123456
$array1 = array("b", "f", "g", "a", "c", "d", "e");
$array2 = array("5", "0", "1", "4", "3", "2", "6");
sort($array1);
sort($array2);
echo "<pre> \n";
print_r($array1);
echo "</pre> \n";
echo "<pre> \n";
print_r($array2);
echo "</pre> \n";
echo "<h3 style='font-family:Helvetica'>Combining Arrays</h3>";
$array3 = array_merge($array1, $array2);
for($i = 0; $i < 7; $i++)
{
for($j = 0; $j < 7; $j++)
{
echo $array3[$i] [$j];
}
}
This can not be done by array_merge. Use simple loop.
http://ideone.com/LLdVm