1. read the file content line by line and explode() the items into an array.
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
while (!feof($handle)) {
//read in the line
$line = fgets($handle, 4096);
//explode it into array elements
$linedata = explode('|',$line);
//remove the 1st element cos it's empty
array_shift($linedata);
//remove the last element cos it's empty too
array_pop($linedata);
//store each line into mydataarray
$mydataarray[] = $linedata;
}
fclose($handle);
}
2. Now you have $mydataarray which is an array of arrays, which looks like this.
Array (
'0' => Array ( '0' => 'jack', '1' => '16'),
'1' => Array ( '0' => 'bob', '1' => '19' ) ,
'2' => Array ( '0' => 'nikki', '1' => '17' )
);
3. just use the array_multisort() function, and you should get what you need.
array_multisort($mydataarray, SORT_ASC);
hope that helps