php - How to encode an associative array grouping one of its members? -
how encode associative array grouping 1 of members?
$my_array = array( // customer 1 [0] => array ( [customer_id] => 1 [cutomer_item] => 7 ) [1] => array ( [customer_id] => 1 [cutomer_item] => 9 ) // customer 2 [2] => array ( [customer_id] => 2 [cutomer_item] => 3 ) [3] => array ( [customer_id] => 2 [cutomer_item] => 5 ) );
i wanto group (csv) customers_items like:
[ // customer 1 { "customer_id" : "1" // customer id preserved "cutomer_items" : "7,9" // customer items imploded comma } , // customer 2 { "customer_id" : "2" "cutomer_items" : "3,5" } ]
i got confused many array functions (http://php.net/manual/en/ref.array.php).
you can use group_concat function in mysql query. if u fetching result through mysql
Comments
Post a Comment