Skip to content

Instantly share code, notes, and snippets.

@alexfurr
Last active February 19, 2019 13:47
Show Gist options
  • Save alexfurr/7c24a2e01f919ee2d0f2a1d0928ebc7d to your computer and use it in GitHub Desktop.
Save alexfurr/7c24a2e01f919ee2d0f2a1d0928ebc7d to your computer and use it in GitHub Desktop.
Sorts a multidimensional array by value given the key name
$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