Page 1 of 1

multisort_array.. I think?

Posted: Fri Jul 26, 2002 11:46 pm
by lc
Ok lemme pose this.

I have several lines in a textfile in a format like below

number|name|date
number|name|date

Now I retrieve the data with a simple

$file = file("textfile.txt");

But I want to have the data sorted... Sorting by number is easy since I can just do a:
$file = nsort($file);
sorta thingy.

But what to do when I want it to be sorted by the name or date??? I think i'd need to first place it in a sub array by doing my regular explode... but what then? I think multisort but I really do not see how to apply it here.

or can I make a sort function read between two specific |'s ?

I'd love some help. ;)

Posted: Sat Jul 27, 2002 3:25 am
by daemorhedron
Well you can loop through the results of the file() command and use the list() command to help setup an array that will allow you to sort it the way you want.

An example :
<?php
$source="1|daemorhedron|today";
list($data['number'],$data['name'],$data['date'])=explode('|',$source);
print_r($data);
?>

Then you could use something like array_multisort to your advantage. It may be helpfule for you to use a var_export() on the original data, save it and then include() that data, but this raises potential security notions, and may not work with your setup.

HTH.