Created
August 8, 2017 07:05
-
-
Save rahuldadhich/bc59a87fd6d0b7a3c9b9a4188f31dc2a to your computer and use it in GitHub Desktop.
Array sort by key
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
$data_array = array( | |
array( | |
'ItemRef' => 20, | |
'ClassRef' => 'test1', | |
'Hours' => 20 | |
), | |
array( | |
'ItemRef' => 21, | |
'ClassRef' => 'test2', | |
'Hours' => 10 | |
) | |
); | |
// array sort by Hours | |
usort($data_array, function ($item1, $item2) { | |
if ($item1['Hours'] == $item2['Hours']) return 0; | |
return $item1['Hours'] < $item2['Hours'] ? -1 : 1; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment