How to merge two array and sum the value : <p>Here is my array</p>

<pre><code>array(5) {
    [0]=&gt;
        array(3) {
        ["product"]=&gt;
        string(14) "apple"
        ["quantity"]=&gt;
        int(1)
        ["color"]=&gt;
        string(5) "red"
    }
    [1]=&gt;
        array(3) {
        ["quantity"]=&gt;
        int(1)
        ["color"]=&gt;
        string(6) "red"
        ["product"]=&gt;
        string(17) "berry"
    }
    [2]=&gt;
        array(3) {
        ["quantity"]=&gt;
        int(5)
        ["color"]=&gt;
        string(6) "green"
        ["product"]=&gt;
        string(14) "apple"
    }
    [3]=&gt;
        array(3) {
        ["quantity"]=&gt;
        int(5)
        ["color"]=&gt;
        string(6) "red"
        ["product"]=&gt;
        string(14) "apple"
    }
    [4]=&gt;
        array(3) {
        ["quantity"]=&gt;
        int(4)
        ["color"]=&gt;
        string(5) "red"
        ["product"]=&gt;
        string(14) "apple"
    }
}
</code></pre>

<p>I want to sum the quantity if they are sample product and same quantity.
Red Apple x 1 and Red apple x 4 and Red Apple x 5 will be merged to Red Apple x 10 , But Green Apple will keep.</p>

<p>How can I do this ?</p>
