Re: Array Sorting

From: Date: Fri, 05 May 2006 01:39:53 +0000
Subject: Re: Array Sorting
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-235602@lists.php.net to get a copy of this message
On Thu, May 4, 2006 10:20 am, James Nunnerley wrote: > $file_array[$filename] = array ("Date" => $Date, "size" => $size, > "permissions" => $permissions); > > I can quite happily sort the array by filename (using natksort and > natkrsort), which I found on the php manual - and for reference have > included as a PS!!!! > > What I'm not sure about doing is sorting by say Size or Date? If size is an integer, then, like, just plain old 'sort' should do it, though it's up to you to figure out the multi-dimensional bit. For dates, there are several possiblities... If you Date happens to be Unix timestamp, it's an integer, and is solved by the above. If your Date happens to be in a format not unlike 'Y/M/D' it can be sorted with plain old sort as a string. In situations where Date is in a more natural format, you can use http://php.net/usort and define your own comparison function any which way you want. All that aside, if, like most, this data is coming from the database, you should just use your SQL query to sort the data, if possible, as it will be MUCH more efficient. YMMV -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#235602) next »