Page 1 of 1

Sorting String Problem

Posted: Fri Oct 18, 2002 3:35 am
by adcworks
Hi,

I am using a flat file text database system to store records of information. A sample in the file would look like this;

1#apple#10/10/02
2#banana#10/10/02
3#cherry#10/10/02

In order to remove items, I read the file per row into a list( ) and then skip the one to remove. I then have another array where I build up the non-skipped ones.

My problem is that I want to be able to sort on any of the 3 "columns" i.e the id, name or date.

When I have my final array $ar I issue a sort and because each element contains a string, it sorts on the id.

Can anyone suggest an alternative way of doing this? I don't really want to reorder the list but I guess I could???

Many thanks.

Posted: Fri Oct 18, 2002 9:03 am
by volka
do you read lines as they are or do you parse the fields with something like fgetcsv()
in any case you might be interested in usort()