Merging and combining arrays in PHP
<p>I have multiple associative arrays, similar to the following:</p>

<pre><code>$arr1 = array(0 =&gt; 12, 5 =&gt; 10, 19 =&gt; 48);
$arr2 = array(0 =&gt; 14, 7 =&gt; 9, 12 =&gt; 11, 19 =&gt; 30);
</code></pre>

<p>I would like to merge these arrays so that I have a single set of keys (0, 5, 7, 12, 19) and each points to an array with the values from the original arrays, and <code>null</code> if the value doesn't exist in the original array:</p>

<pre><code>$merge = array(
    0 =&gt; array(12, 14),
    5 =&gt; array(10, null),
    7 =&gt; array(null, 9),
    12 =&gt; array(null, 11),
    19 =&gt; array(48, 30)
);
</code></pre>

<p>I need to be able to do this for an arbitrary number of arrays. I'm not sure where to start with this. </p>

<p>I could, I suppose, iterate through each array, append it's value to the result - but I'd have to check to see if I have the requisite number of elements in each resulting array before appending the current value to that index - which isn't terribly efficient.</p>

<p>Ideas or pointers?</p>
