PHP - Merge inner arrays within a multi-dimensional array if a specific element matches : <p>I have an array of arrays:</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [product_id] =&gt; 1
            [name] =&gt; size
            [lang_key] =&gt; en
            [value] =&gt; Medium
        )

    [1] =&gt; Array
        (
            [product_id] =&gt; 1
            [name] =&gt; colour
            [lang_key] =&gt; en
            [value] =&gt; Orange
        )

    [2] =&gt; Array
        (
            [product_id] =&gt; 2
            [name] =&gt; size
            [lang_key] =&gt; en
            [value] =&gt; Medium
        )

    [3] =&gt; Array
        (
            [product_id] =&gt; 2
            [name] =&gt; colour
            [lang_key] =&gt; en
            [value] =&gt; Green
        )

    [4] =&gt; Array
        (
            [product_id] =&gt; 3
            [name] =&gt; size
            [lang_key] =&gt; en
            [value] =&gt; Medium
        )

    [5] =&gt; Array
        (
            [product_id] =&gt; 3
            [name] =&gt; colour
            [lang_key] =&gt; en
            [value] =&gt; Pink
        )

)
</code></pre>

<p>As you can see there are six inner arrays and the product_id field matches twice for each value, so there are three pairs.</p>

<p>I'd like to merge the "name" and "value" fields of each inner array into just the value field if the "product_id" field matches.</p>

<p>I'm aiming to end up with this:</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [product_id] =&gt; 1
            [lang_key] =&gt; en
            [value] =&gt; Size: Medium, Colour: Orange
        )

    [1] =&gt; Array
        (
            [product_id] =&gt; 2
            [lang_key] =&gt; en
            [value] =&gt; Size: Medium, Colour: Green
        )

    [2] =&gt; Array
        (
            [product_id] =&gt; 2
            [lang_key] =&gt; en
            [value] =&gt; Size: Medium, Colour: Pink
        )
)
</code></pre>

<p>Which PHP function should I be using and how?</p>
