Last active
February 19, 2019 13:47
-
-
Save alexfurr/7c24a2e01f919ee2d0f2a1d0928ebc7d to your computer and use it in GitHub Desktop.
Sorts a multidimensional array by value given the key name
This file contains 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
$arrayItems = array( | |
array ("date" => "2018-10-21", "grade" => 50), | |
array ("date" => "2018-04-02", "grade" =>88), | |
array ("date" => "2018-03-17", "grade" =>76), | |
array ("date" => "2018-03-10", "grade" =>84), | |
array ("date" => "2019-02-03", "grade" =>67), | |
); | |
// Obtain a list of columns - last value is the key | |
$myCols = array_column($arrayItems, 'date'); | |
array_multisort($myCols, SORT_DESC, $arrayItems); | |
print_r($arrayItems); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment