Skip to content

Instantly share code, notes, and snippets.

@kingpabel
Created October 31, 2015 23:04
Show Gist options
  • Save kingpabel/6747d63864d6be8262b3 to your computer and use it in GitHub Desktop.
Save kingpabel/6747d63864d6be8262b3 to your computer and use it in GitHub Desktop.
<?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