[thelist] php - sorting multidimensional arrays

Phil Cooper Phil.Cooper at zirconsoftware.co.uk
Tue Sep 28 06:48:01 CDT 2004

> In PHP, you can do this using usort, and defining your own 
> sorting criteria:
> http://www.php.net/manual/en/function.usort.php
> Given that you are pulling the data from a MySQL table, it could also
> be possible for you to add an ORDER BY to the query, and get the data
> in the correct order straight from the database.
> Tim

Thanks for that - I'll have a read and see if I can understand it.  Would this method allow you to sort say by 'wins' and then by 'pf'?

Not all the data in the arrays is direct from the mysql table.  I had thought about doing the data manipulation and then sending it to a new table and then querying that using ORDER BY but thought it must be possible to do the sorting in php so I didn't have to query the database twice.  Out of interest which method is more programmatically correct?

More information about the thelist mailing list