I have an array as follows:
Array(
[27] => \'Sarah Green\',
[29] => \'Adam Brown\',
[68] => \'Fred Able\'
);
I\'d like
function sortByLastName($a){
$tmp = $a;
foreach($tmp as $k => $v){
$tmp[$k] = substr($v,strrpos($v, ' ')+1);
}
asort($tmp);
$ret = array();
foreach($tmp as $k => $v){
$ret[$k] = $a[$k];
}
return $ret;
}
Maybe not the fastest way but it works. It works if they have middle names too.
This is faster than the accepted answer.
http://codepad.org/ogGibRpH