Jump to content

Sort multidimensional array and retain index associations?


Pikachu2000

Recommended Posts

I have a text file that gets parsed into a multidimensional array of several hundred sub-arrays of 40+ elements each. I'd like to sort by the value of an element in the sub-arrays, and retain the index associations. I know I could dump this into a mySQL table and pull it out again, but the file is updated every 5 minutes, and I have no control over it. A (simplified) example of the print_r() would be like below. I'd like to be able to sort by any one of the sub-array's element values for display on a web page (able to be resorted by clicking the column heading). Is there a simple solution that I'm missing by over-thinking this, or would it actually be more efficient to database it, then just run a cron job to get rid of the obsolete records?

 

 

Array (
[0] => Array ( [0] => 0666 [1] => 1075877 [2] => Spain [3] => Bob )
[1] => Array ( [0] => 4X-PMO [1] => 1129059 [2] => Italy [3] => Tom )
[2] => Array ( [0] => 7774R [1] => 848472 [2] => France [3] => Brenda )
[3] => Array ( [0] => 85633 [1] => 1155488 [2] => Maldives [3] => Steve )
[4] => Array ( [0] => 85645 [1] => 1084173 [2] => Brasilia [3] => Molly )
)

Nevermind. I just decided that flexibility is going to take precedence, and it's going to get dumped into a DB table. Then I can sort and paginate and whatever I need to do without issues or complications. In that manner, I can also archive the records for trend analysis if I decide to do that at some point.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.