Re: Sorting a PHP array

From: Date: Wed, 15 May 2013 17:10:06 +0000
Subject: Re: Sorting a PHP array
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-48743@lists.php.net to get a copy of this message
On 5/15/2013 12:32 PM, 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
Sure you can sort this array, but you'd have to write your own I think. Why not just order a query and use those results instead of an array? A query should process pretty fast on almost any system. Are you in need of such instantaneous response that you thought of going to an array? You could have this query: $q = "select author,title,year,media ... from books_table order by '$sortkey'" where $sortkey can be a desired field name chosen by the user. Could be a multi-fieldname sortkey as well. Could be run as an ajax request if need be too. So many better ways of doing this than an array IMHO.

« previous php.db (#48743) next »