Created
December 4, 2019 10:55
-
-
Save gagimilicevic/2b8bfc86773e6d32f4cee33af6a4c09d to your computer and use it in GitHub Desktop.
PHP sort associative array
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
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