Created
October 31, 2015 23:04
-
-
Save kingpabel/6747d63864d6be8262b3 to your computer and use it in GitHub Desktop.
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
<?php | |
//example | |
$array = [ | |
[ | |
'foo' => 5.5, | |
'bar' => 'abc' | |
], | |
[ | |
'foo' => 7.7, | |
'bar' => 'xyz' | |
], | |
[ | |
'foo' => 2.2, | |
'bar' => 'efg' | |
] | |
]; | |
// Sort $array by 'foo' property, ascending | |
usort($array, function ($a, $b) { | |
return $a['foo'] <=> $b['foo']; | |
}); | |
// Sort $array by 'bar' property, descending | |
usort($array, function ($a, $b) { | |
return $b['bar'] <=> $a['bar']; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment