Would appreciate any help with this.:)
I have the following text file:
roomA Springer, Jerry js@email.com
roomB Cruise, Tom tc@email.com
roomC Jovi, Bon bj@email.com
and I want to sort it by the surname so it outputs:
Cruise, Tom roomB tc@email.com
Jovi, Bon roomC bj@email.com
Springer, Jerry roomA js@email.com
I know how to load the file:
$a = file("details.txt");
and think I have to use explode() to split up the data (tab-seperated):
$array = explode("\t", $a);
this makes the name the second element in the array.
How do I put the string back together with the name coming first, followed by the room and email?
Thanks.
Do a
var_dump($array)and it will display you the indexes. You then only need to swap two elements with each other. Here is a trick:After that, you can
implodethe result as you didexplodeit:Hope this is helpful. Ah well, and for sorting, take a look at
array_multisort.