You can use [man]array_multisort/man to handle this. Check out the below code, maybe it's not the best way, but it works!
<?php
$datafile = "data.txt";
$data = file($datafile);
for ($i=0;$i<sizeof($data);$i++) {
$rowdata = split("\|",trim($data[$i]));
$newdata[$i] = $rowdata;
$firstname[$i] = $rowdata[1];
}
array_multisort($firstname, $newdata);
var_dump($newdata);
?>
That code returns:
array(3) {
[0]=>
array(4) {
[0]=>
string(1) "3"
[1]=>
string(4) "Joel"
[2]=>
string(5) "Smith"
[3]=>
string(7) "Orlando"
}
[1]=>
array(4) {
[0]=>
string(1) "1"
[1]=>
string(3) "Rob"
[2]=>
string(5) "Jones"
[3]=>
string(7) "Seattle"
}
[2]=>
array(4) {
[0]=>
string(1) "2"
[1]=>
string(3) "Sue"
[2]=>
string(6) "Miller"
[3]=>
string(9) "San Diego"
}
}
Which I belive is what you are looking for. You can then display that data with something like:
foreach ( $newdata as $values ) {
echo "first name: $values[1]<br />";
echo "last name: $values[2]<br />";
echo "city: $values[3]<br />";
echo "------------------------------<br />";
}