How to encode an associative array grouping one of its members?
<p>How to encode an associative array grouping one of its members?</p>

<pre><code>$my_array = Array(
// customer 1
    [0] =&gt; Array
        (
            [customer_id] =&gt; 1
            [cutomer_item] =&gt; 7
        )

    [1] =&gt; Array
        (
            [customer_id] =&gt; 1
            [cutomer_item] =&gt; 9
        )
// customer 2            
    [2] =&gt; Array
        (
            [customer_id] =&gt; 2
            [cutomer_item] =&gt; 3
        )

    [3] =&gt; Array
        (
            [customer_id] =&gt; 2
            [cutomer_item] =&gt; 5
        )

);
</code></pre>

<p>I wanto to <strong>group (csv) customers_items</strong> like:</p>

<pre><code>[
// customer 1
    {
     "customer_id" : "1" // customer id preserved
     "cutomer_items" : "7,9" // customer items imploded with a comma
    }
,
// customer 2
    {
     "customer_id" : "2"
     "cutomer_items" : "3,5"
    }
]
</code></pre>

<p>I got confused with so many array functions (<a href="http://php.net/manual/en/ref.array.php" rel="nofollow">http://php.net/manual/en/ref.array.php</a>).</p>