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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -