Sorting String Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adcworks
Forum Newbie
Posts: 4
Joined: Fri Oct 18, 2002 3:35 am

Sorting String Problem

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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()
Post Reply