how can i group php array by certain key value -


i array this

array (     [0] => array         (             [cat] => cat             [2] => 1         )      [1] => array         (             [dog] => dog             [3] => 1         )      [2] => array         (             [cat] => cat             [4] => 1         )  ) 

but want soemthing this

array (     [0] => array         (             [cat] => cat             [2] => 1             [4] => 1         )      [1] => array         (             [dog] => dog             [3] => 1         ) ) 

i've created in way save keys , everything. let me know if works out :)

<?php     $start = [         ["cat" => "cat", "2" => 1],         ["dog" => "dog", "3" => 1],         ["cat" => "cat", "4" => 1]     ];     $end = [];      foreach($start $key => $array) {         if(!isset($end[current($array)])) {             $name = current($array);              $end[$name][key($array)] = $name;             next($array);             $end[$name][key($array)] = current($array);         } else {             $name = current($array);              next($array);             $end[$name][key($array)] = current($array);         }     }      $end = array_values($end);      print_r($end); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -