Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Created September 13, 2019 19:06
Show Gist options
  • Save Farmatique/b8ad801a8ab313cae5335cf87449e7d2 to your computer and use it in GitHub Desktop.
Save Farmatique/b8ad801a8ab313cae5335cf87449e7d2 to your computer and use it in GitHub Desktop.
php sort array by name
$api_response_sorted; // initial array
$sortArray = array();
foreach($api_response_sorted as $person){
foreach($person as $key=>$value){
if(!isset($sortArray[$key])){
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
$orderby = "employeeName"; //change this to whatever key you want from the array
array_multisort($sortArray[$orderby],SORT_DESC,$api_response_sorted);
// now $api_response_sorted is sorted by "employeeName"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment