Let's say you have an array that looks like this:
$myArray []= array('firstname' => 'John' , 'lastname'=> 'Johnson');
$myArray []= array('firstname' => 'Adam' , 'lastname'=> 'Tyson');
$myArray []= array('firstname' => 'Mike' , 'lastname'=> 'Robinson');
$myArray []= array('firstname' => 'David' , 'lastname'=> 'Jackson');
How can you sort $myArray according to the lastname?
This should do what you need:
I'm using
uasort()
, one of the custom sort function, to the sorting.I got it to work using usort() and a closure.
This also works