Re: Array Sorting

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

 



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

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux