My suggestion is when you input the data into the database, reverse the way you input the data. For eg, probably a bit patronizing the first part so sorry about that. On the form where you input, have a separate field for both first and last names, input them in reverse order into the database remove any white space then place a comma in between them in the database itself... that make sense?
Instead of:
[title] => Sam Herbert
its:
[title] => Herbert,Sam
you can use this select query to retrieve the data:
"SELECT * FROM tablename ORDER BY title DESC"
and it will order by the title field in alphabetical order.
to get the names separate again is simple too.
eg.
$name_array = explode( "," , $result[3]['title'] );
then $name_array is exactly what it says and you can echo out both the first and last name independently.
echo $name_array[0]; //Herbert
echo $name_array[1]; //Sam
basic script example(untested):
//data is array 3 in the data you provided, but with the changes I placed there (assume all the data that you provided was gathered)
//so Sam is array spot 0, then pat, DJ then Boo (assuming that boos last name is 'Sze Yang')
$select = "SELECT * FROM users ORDER BY title DESC";
$query = mysqli_query($link, $select);
$d_array = mysqli_fetch_array($query, 1);
$d_array[3]['title'] = explode("," , $d_array[3]['title']);
echo $d_array[0]['title'][0]; //Herbert
echo $d_array[0]['title'][1]; //Sam
I haven't tested it but i can't see why it wouldn't work.
A little foreach statement or something would work well there, although I think you already know that 🙂
GL im going to bed its 3am, and if that didn't make sense at all, im sorry but im tired 😃