Array: {code...} How to convert the above array? {Code...} array:
Array ([0] => Array ([id] => 1 [menu_collapse] => Super menu [menu_items] => write an article [cid] => 1) [1] => Array ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Manage data [cid] => 2) [2] => Array ([id] => 3 [menu_collapse] => Maintenance Menu [menu_items] => Management user [cid] => 2 ))
How to convert the above array?
Array ([0] => Array ([id] => 1 [menu_collapse] => Super menu [menu_items] => write an article [cid] => 1) [1] => Array ([new] => Array ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Manage data [cid] => 2) ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Manage data [cid] => 2 ))
Reply content:
Array:
Array ([0] => Array ([id] => 1 [menu_collapse] => Super menu [menu_items] => write an article [cid] => 1) [1] => Array ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Manage data [cid] => 2) [2] => Array ([id] => 3 [menu_collapse] => Maintenance Menu [menu_items] => Management user [cid] => 2 ))
How to convert the above array?
Array ([0] => Array ([id] => 1 [menu_collapse] => Super menu [menu_items] => write an article [cid] => 1) [1] => Array ([new] => Array ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Manage data [cid] => 2) ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Manage data [cid] => 2 ))
$ Arr = [['id' => 1, 'menu _ collapse' => 'supermenu ', 'menu _ items' => 'write an write ', 'CID' => 1,], ['id' => 2, 'menu _ collapse' => 'maintenance menus ', 'menu _ items '=> 'Manage data', 'CID' => 2,], ['id' => 3, 'menu _ collapse' => 'maintenance menus ', 'menu _ items' => 'Manage users', 'CID' => 2,]; $ result = []; $ res = []; foreach ($ arr as $ k => $ v) {$ result [$ v ['CID'] [] = $ v ;} foreach ($ result as $ key => $ value) {if (count ($ value) = 1) {$ res [$ key] = $ value [0];} else {$ res [$ key] ['new'] = $ value ;}} echo'
'; Print_r (array_values ($ res )); /* Array ([0] => Array ([id] => 1 [menu_collapse] => Super menu [menu_items] => write an article [cid] => 1) [1] => Array ([new] => Array ([0] => Array ([id] => 2 [menu_collapse] => Maintenance Menu [menu_items] => Management data [cid] => 2) [1] => Array ([id] => 3 [menu_collapse] => Maintenance Menu [menu_items] => Management user [cid] => 2 ))))*/
You can only traverse the array for processing.