Created
September 13, 2019 19:06
-
-
Save Farmatique/b8ad801a8ab313cae5335cf87449e7d2 to your computer and use it in GitHub Desktop.
php sort array by name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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