I have these 3 arrays:
$a1 = array( 'a' => 1, 'b' => 2, 'c' => 3 );
$a2 = array( 'a' => 4, 'b' => 5, 'd' => 6 );
$a3 = array( 'a' => 7, 'c' => 8, 'd' => 9, 'x' => 10 );
I want to merge them so the result looks like this:
Array(
[a] => Array(
[0] => 1
[1] => 4
[2] => 7
)
[b] => Array(
[0] => 2
[1] => 5
[2] =>
)
[c] => Array(
[0] => 3
[1] =>
[2] => 8
)
[d] => Array(
[0] =>
[1] => 6
[2] => 9
)
[x] => Array(
[0] =>
[1] =>
[2] => 10
)
... and I will be using the data in a simple table like this:
col-1 col-2 col-3
a 1 4 7
b 2 5 -
c 3 - 8
d - 6 9
x - - 10
array_merge_recursive is close, but doesn't give me the empty elements, so I believe I need a loop to get the job done. My problem is figuring out which function I need to use in that loop.
I'd be happy just to merge 2 arrays at a time with a custom user function.