This is the first part of the array (derived from a JSON feed). The repeating blocks are inside [Attendee], and start at [0].
Array
(
[Code] => 1
[Message] => Successfully retrieved data
[Result] => Array
(
[Attendee] => Array
(
[0] => Array
(
[CountryCode] => 44
[DemographicData] => Array
(
)
[Email] => firstname.lastname@server.com
[FreeTextDataCategories] => Array
(
[AttendeeFreeTextDataCategory] => Array
(
[0] => Array
(
[DataCategoryId] => 165497
[Value] => Firstname
)
[1] => Array
(
[DataCategoryId] => 165498
[Value] => Lastname
)
[2] => Array
(
[DataCategoryId] => 165500
[Value] => Job Title
)
[3] => Array
(
[DataCategoryId] => 165504
[Value] => Array
(
)
)
)
)
[GuestOfAttendeeId] => Array
(
)
[Id] => 3344468
[Name] => Firstname Lastname
[Password] => Array
(
)
[PhoneNumber] => 123456789
[RegisteredVia] => Email
[RegistrationDate] => 2017-06-30T11:30:44.313
[SessionId] => 111222333
[Status] => Registered
[StatusDate] => 2017-06-30T11:30:44.313
)
)
)
I want to sort the Attendee[n] by Lastname, a value I can easily echo, but I can't understand how to sort by it. Here's how I echo it:
foreach ($result_array['Result']['Attendee'] as $row) {
echo "<a href=\"mailto:" . $row["Email"] . "\">" . $row["FreeTextDataCategories"]["AttendeeFreeTextDataCategory"][0]["Value"] . " " . $row["FreeTextDataCategories"]["AttendeeFreeTextDataCategory"][1]["Value"]. " </a>"; }
I have searched for existing questions and tried to adapt my case to solutions like these, but without success: Sorting Complex Arrays by Name - Sort multidimensional array alphabetically - PHP Array Complex Sort