I have the following problem: As you can see on the picture, I have a drop down box that is not sorted alphabetically by country or city.
The JSON object
looks like this:
[{"HAM": {Name: "Hamburg", Country: "Germany", ...},
"DEL": {Name: "Delhi", Country: "India", ...}, etc.}]
In PHP
it is assembled inside a loop as follows:
$locations[$locationCode] = [
'name' => $locationName,
'type' => $locationObject->getType(),
country' => $this->getCountryForLocation($locationName),
'accessSizes' => $accessSizes,
'services' => $services
]
How can I sort the countries alphabetically first and then the cities in jQuery
or PHP
? I would prefer to do this in PHP
.
My problem is that I try it outside the loop and so I don't know the $locationCode
anymore. Can anyone help me? I tried array_multisort()
to bypass the $locationCode
but unfortunately it never worked.