I have a multidimensional array in PHP that I am trying to alphabetize. I am trying to sort the students by alphabetical order by last name. Students are listed inside of $array['students'], but the ['submissions'] inside of each student needs to stay with that student after the sort is over.
I have tried using uasort($array['students'], 'cmp')
but this does not return anything at all.
Basically, I need to alphabetize the students array. I'm not sure how to do this since I would be using a value to organize, and since this is a multidimensional array. Any help would be appreciated.
Array structure:
$array['assignments'][assignmentID][details]
$array['students'][studentID][details]
$array['students'][studentID]['submissions'][assignmentID][details]
Here is the output from print_r($array)
Array
(
[assignments] => Array
(
[9] => Array
(
[assEmoji] => ✏️
[title] => Roanoke Story Map
[points] => 10
[assigned] => 2021-08-16
[due] => 2021-08-20 15:00:00
)
)
[students] => Array
(
[11] => Array
(
[firstName] => John
[lastName] => Smith
[fullName] => John Smith
[earned] => 103
[maxpts] => 120
[submissions] => Array
(
[9] => Array
(
[workID] => 539
[status] => graded
[submitted] => 2021-08-17 08:15:48
[method] => wall
[score] => 9
[points] => 10
[graded] => 2021-09-22 10:26:54
)
)
)
[12] => Array
(
[firstName] => Amy
[lastName] => Appleton
[fullName] => Amy Appleton
[earned] => 91
[maxpts] => 110
[submissions] => Array
(
[9] => Array
(
[workID] => 540
[status] => graded
[submitted] => 2021-08-17 08:45:48
[method] => wall
[score] => 7
[points] => 10
[graded] => 2021-09-22 10:28:54
)
)
)
[13] => Array
(
[firstName] => Zeke
[lastName] => Lee
[fullName] => Zeke Lee
[earned] => 91
[maxpts] => 110
[submissions] => Array
(
[9] => Array
(
[workID] => 540
[status] => graded
[submitted] => 2021-08-17 08:45:48
[method] => wall
[score] => 7
[points] => 10
[graded] => 2021-09-22 10:28:54
)
)
)
)
)