I donβt think you could directly do this using the built-in sorting of PHP arrays, although I would be interested if someone fixed me.
The easiest way is to change the names to turn green, Sarah, because then you could use your own PHP sort functions, for example. using asort () (which supports key association).
If this is not possible, you will probably need to implement your own sort function. The easiest way to do this is to use usort (), which allows you to define a custom comparator function. For example:
usort($arr, "sortByLastName"); function sortByLastName($a, $b) {
source share