Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Created July 1, 2015 16:11
Show Gist options
  • Save alancoleman/4a4977b6376cf2c32846 to your computer and use it in GitHub Desktop.
Save alancoleman/4a4977b6376cf2c32846 to your computer and use it in GitHub Desktop.
Sorting a multidimensional array
/*
array (size=4)
0 =>
array (size=2)
'screen_id' => string 'A0E6457F-EF4F-4BEF-811A-0ACE00AE6225' (length=36)
'name' => string 'Level 1 - Stalls' (length=16)
1 =>
array (size=2)
'screen_id' => string 'A34D24F8-B1C5-4E26-A1FE-91A3C13A4F10' (length=36)
'name' => string 'Level 2 - Dress Circle' (length=22)
2 =>
array (size=2)
'screen_id' => string '9C433821-1F3D-4685-94D0-F0020597A7C5' (length=36)
'name' => string 'Level 3 - Royal Circle' (length=22)
3 =>
array (size=2)
'screen_id' => string '2AE67063-A1B3-4521-BAB9-1B38BC9DBCA7' (length=36)
'name' => string 'Level 4 - Balcony' (length=17)
*/
function cmp($a, $b) {
return strcmp($a['name'], $b['name']);
}
usort($arr, 'cmp');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment