My API written in PHP (Codeigniter) outputs users based on a selected keyword how can I sort this array in alphabetical order before it outputs to JSON.
This is the outp
This one works. Tried, tested, and true:
function sort_by_lastname($a, $b) { $a = trim($a['user']['basic'][0]['lastname']); $b = trim($b['user']['basic'][0]['lastname']); return strcmp($a,$b); } uasort($array['contacts'],'sort_by_lastname');