This code works great, until something is case sensitive. I've tried using strnatcasecmp instead of the cmp, and it grabs the whole string not the last name. any suggestions on how to write this better?
for example the current order is:
Aaron Carson
Adam Davidson
Jen Hennings
ektor bluemouth
I want ektor bluemouth to be on top.
foreach($connected->posts as $p) {
$lastname = explode(' ', $p->post_title);
if(sizeof($lastname) == 1) {$p->lastname = $lastname[0];}
if(sizeof($lastname) == 2) {$p->lastname = $lastname[1];}
if(sizeof($lastname) == 3) {$p->lastname = $lastname[2];}
}
usort($connected->posts, 'cmp');
I would do something like this
It could be adapted to work with your data format
Best to create
$aOrderedPosts
when you create/read in the post objects from DB. Additionally I would create it as a property of theconnection
class.