Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created December 4, 2019 10:55
Show Gist options
  • Save gagimilicevic/2b8bfc86773e6d32f4cee33af6a4c09d to your computer and use it in GitHub Desktop.
Save gagimilicevic/2b8bfc86773e6d32f4cee33af6a4c09d to your computer and use it in GitHub Desktop.
PHP sort associative array
While others have correctly suggested the use of array_multisort(),
for some reason no answer seems to acknowledge the existence of array_column(),
which can greatly simplify the solution. So my suggestion would be:
array_multisort(array_column($inventory, 'price'), SORT_DESC, $inventory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment