Sort By Last Name
This is the best my sun-baked brain could conjure on a few hours' sleep. The database stores "name" entries which can have anything in them (no, I didn't write the validation for this and my "why don't you add a firstname & lastname field" idea got vetoed). They want to sort on the last name which, to me, means the last token after splitting on white space. Right?
foreach ($entries as $entry) {
$tokens = split(' ', $entry);
if (count($tokens) > 1) {
$name_sort[$tokens[count($tokens) - 1] . microtime()] = $entry;
}
}
$keys = array_keys($name_sort); asort($keys);
foreach ($keys as $key) { $names[] = $name_sort[$key]; }
