3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function printPerson($person) { sprintf( "Name: %s | Age: %s | Color: %s <br />", $person["name"], $person["age"], $person["colour"] ); } $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 foreach ($arrSortArray[$orderby] as $person) { printPerson($person); } array_multisort($arrSortArray[$orderby], SORT_ASC,$people); foreach ($arrSortArray[$orderby] as $person) { printPerson($person); }
based on uEvu7
Output for 4.3.0 - 7.1.0