I tried to search and found this:
Sort an array by a child array's value in PHP
But the function does not work in my case:
$sorted = array();
foreach($players as $player)
{
$p = Model::factory('user');
$p->load($player['id']);
$sorted[] = array('id' => $player['id'], 'username' => $p->get_username());
}
How can i sort the array alphabetic after the username?
The function,
function cmp($a, $b) {
if ($a['username'] == $b['username']) {
return 0;
}
return ($a['username'] < $b['username']) ? -1 : 1;
}
and then calling usort($sorted,"cmp"); will not work out for me (getting error undefined index[2])..
And is there any way to choose whether it should be sorting descending or ascending?