Array sorting question
Posted: Mon Nov 06, 2006 8:38 pm
Hi,
Question: I have this text file that I want to sort according to cart letter (cart A, cart B ...). I was looking though the different array sort options and did not really see anything that met my needs. How would I sort, by cart letter, the following type of information keeping all relevant data together? Or do I have to do this using a database instead of a text file.
a:3:{s:4:"name";s:10:"Bill Gates";s:4:"cart";s:6:"Cart A";s:4:"date";s:10:"11/07/2008";}
a:3:{s:4:"name";s:10:"Mike Bibby";s:4:"cart";s:6:"Cart D";s:4:"date";s:10:"11/08/2006";}
a:3:{s:4:"name";s:8:"Joe Blow";s:4:"cart";s:6:"Cart A";s:4:"date";s:10:"11/08/2006";}
a:3:{s:4:"name";s:12:"Mike Schmeer";s:4:"cart";s:6:"Cart B";s:4:"date";s:10:"11/08/2006";}
I was thinking about the natural sort option but don't know how I could get this to work.
Could I read all the relevant info into an array? So for example after reading the text file, unserializing it and looping through it, could I then store all the info into an array such as $info and then use natsort($info['cart']). Would that work or is that not a way you can use natsort()?
As always, thank you so much for your help.
And yes, I know I should be using mysql for a database but I'm not quite there yet, though it looks like I may have to go that way soon.
Question: I have this text file that I want to sort according to cart letter (cart A, cart B ...). I was looking though the different array sort options and did not really see anything that met my needs. How would I sort, by cart letter, the following type of information keeping all relevant data together? Or do I have to do this using a database instead of a text file.
a:3:{s:4:"name";s:10:"Bill Gates";s:4:"cart";s:6:"Cart A";s:4:"date";s:10:"11/07/2008";}
a:3:{s:4:"name";s:10:"Mike Bibby";s:4:"cart";s:6:"Cart D";s:4:"date";s:10:"11/08/2006";}
a:3:{s:4:"name";s:8:"Joe Blow";s:4:"cart";s:6:"Cart A";s:4:"date";s:10:"11/08/2006";}
a:3:{s:4:"name";s:12:"Mike Schmeer";s:4:"cart";s:6:"Cart B";s:4:"date";s:10:"11/08/2006";}
I was thinking about the natural sort option but don't know how I could get this to work.
Could I read all the relevant info into an array? So for example after reading the text file, unserializing it and looping through it, could I then store all the info into an array such as $info and then use natsort($info['cart']). Would that work or is that not a way you can use natsort()?
As always, thank you so much for your help.
And yes, I know I should be using mysql for a database but I'm not quite there yet, though it looks like I may have to go that way soon.