Data sorting

Soldato
Joined
24 Nov 2002
Posts
16,378
Location
38.744281°N 104.846806°W
I have two columns of information, A which is an ID and B which is a value.

I wish to sort this so that any multiple ID's are given a 'multiple' value..

e.g.

A B
1 apples
2 oranges
2 pears
2 bananas
3 strawberries
4 grapes
4 kiwi
5 lychees

Would become:
A B
1 apples
2 multiple
3 strawberries
4 multiple
5 lychees

Any ideas?

PHP would be nicest as the source data is tab. delim.

Cheers!

JD
 
Associate
Joined
21 Sep 2005
Posts
180
Location
Dundee
Couldn't you use Column A as the key of an associative array? The array could then be populated as you iterate through your input. For each item in Column A, you would check the keys of the array, if it is present already then you would make the value against that key equal 'multiple'. Else, enter the key and the value. Then when data input is complete, iterate through the array to get your columns of results.

There is probably an easier way but i'm not the most elegant of coders. :D
 
Top