You need array_multisort. Something like this, although you'd need to work out how to select the sort you want (presumably based on a form input).
$fcontents = file("file.txt");
while (list ($line_num, $line) = each ($fcontents)) {
// split line
$field = explode("||", $line);
// build up separate arrays
$id[] = $field[0];
$time[] = $field[1];
$subject[] = $field[2];
$sender[] = $field[3];
}
array_multisort ($time,$subject,$sender,$id);
or
array_multisort ($subject,$time,$sender,$id);
or
array_multisort ($sender,$time,$subject,$id);
The sort is on the first array's contents, with the others used to resolve equal sort keys. The contents of all the arrays are sorted along with the first one.
I was using this as a laborious way to reverse a file's contents until I realised that there is an array_reverse function ... !