Skip to content

Instantly share code, notes, and snippets.

@rahuldadhich
Created August 8, 2017 07:05
Show Gist options
  • Save rahuldadhich/bc59a87fd6d0b7a3c9b9a4188f31dc2a to your computer and use it in GitHub Desktop.
Save rahuldadhich/bc59a87fd6d0b7a3c9b9a4188f31dc2a to your computer and use it in GitHub Desktop.
Array sort by key
$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