3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $people = array( array("name"=>"Bob","age"=>8,"colour"=>"red"), array("name"=>"Greg","age"=>12,"colour"=>"blue"), array("name"=>"Andy","age"=>5,"colour"=>"purple") ); $arrSortArray = array(); foreach($people as $person) { foreach($person as $key=>$value){ if(!isset($arrSortArray[$key])){ $arrSortArray[$key] = array(); } $arrSortArray[$key][] = $person; } } $orderby = "name"; //change this to whatever key you want from the array var_dump($arrSortArray[$orderby]); array_multisort($arrSortArray[$orderby], SORT_ASC,$people); var_dump($arrSortArray[$orderby]);
based on oeKaC
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> array(3) { ["name"]=> string(3) "Bob" ["age"]=> int(8) ["colour"]=> string(3) "red" } [1]=> array(3) { ["name"]=> string(4) "Greg" ["age"]=> int(12) ["colour"]=> string(4) "blue" } [2]=> array(3) { ["name"]=> string(4) "Andy" ["age"]=> int(5) ["colour"]=> string(6) "purple" } } array(3) { [0]=> array(3) { ["name"]=> string(4) "Andy" ["age"]=> int(5) ["colour"]=> string(6) "purple" } [1]=> array(3) { ["name"]=> string(3) "Bob" ["age"]=> int(8) ["colour"]=> string(3) "red" } [2]=> array(3) { ["name"]=> string(4) "Greg" ["age"]=> int(12) ["colour"]=> string(4) "blue" } }