I have three arrays that I want to combine into one 2D array.
Each array has a code/value pair. The codes are the same in each array, but all codes may not be present in each array.
Each array is:
$array1 = array ("a1" => "22", "c2" => "17", "d1" => "5", "e3" => "101");
$array2 = array ("b1" => "4", "f1" => "6", "g1" => "3", "h1" => "10");
$array3 = array ("c2" => "8", "d1" => "9", "e3" => "1", "g1" => "2");
I want to combine these into one 2D array, that would look like this:
$array2D = array(
"a1" => array(22,0,0),
"b1" => array(0,4,0),
"c2" => array(17,0,8),
"d1" => array(5,0,9),
"e3" => array(101,0,1),
"f1" => array(0,6,0),
"g1" => array(0,3,2)
);
I tried
$array2D = array_merge_recursive($array1, $array2, $array3);
But this does not put the values in the correct position, it puts the values in the first position... For example, it puts:
[c2] => Array
(
[0] => 17
[1] => 8
)
but it should be:
[c2] => Array
(
[0] => 17
[1] => 0
[2] => 8
)
Any ideas?