Re: Sorting a PHP array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I would use ORDER BY in your query and let the database do the work, assuming you're using a standard relational database (like MySQL or Postgresql).

Otherwise, if you MUST do it in PHP, you could look at usort(), or uasort() using your own custom sorting function. I would, however, strongly recommend keeping the work in the database. (If you're using a bleeding-edge version of PHP (I think this is in the 5.5 release candidates), you could also use array_column() along with usort() or uasort() to make your life easier.)


-Matt

On 05/15/2013 09:32 AM, Charlie Lewis wrote:
I have a bookseller database list read into a PHP array with dimensions
[row][field]. There are 32 fields in each record/row and up to 500 records.

What is the neatest way to sort the array by any of the fields, such as
author or title?

I know I should just search for a manual on this, but could anybody give me
a quick start?

Thanks,

Charlie




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux