Merging associate arrays in PHP
<p>I have a serialized array stored in a cookie, at one point in my application I need to merge this array with another array with the same design, so:</p>

<p>Array 1:</p>

<pre><code>$arr1 = array(
            "user_id" =&gt; 1,
            "item_id" =&gt; 2,
            "quant" =&gt; 3
        );
</code></pre>

<p>I set this in a cookie with: </p>

<pre><code>serialize($arr1);
</code></pre>

<p>Array 2:</p>

<pre><code>$arr2 = array(
            "user_id" =&gt; 5,
            "item_id" =&gt; 5,
            "quant" =&gt; 6
        );
</code></pre>

<p>My attempt at merging the two arrays:
First I unserialize the first array value that is in my cookie, followed by a merge with the second array</p>

<pre><code>$un_arr1 = unserialize($cookie_val);
$final = array_merge($arr2, $un_arr1);
</code></pre>

<p>This is returning me only the values from the first array though.</p>

<p>What I am trying to achieve:</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [user_id] =&gt; 1
            [item_id] =&gt; 2
            [quant] =&gt; 3
        )

    [1] =&gt; Array
        (
            [user_id] =&gt; 4
            [item_id] =&gt; 5
            [quant] =&gt; 6
        )
)
</code></pre>
