Posted by Dikkie Dik on 12/01/07 14:46
Ciaran wrote:
> Anyone know how to do this? I have a standard 3D array:
>
> $item[0]['title']
> $item[0]['content']
> $item[0]['date']
> $item[1]['title']
> $item[1]['content']
> $item[1]['date']
> etc...
>
> How do I sort it based on date so the most recent item (the one with
> the highest date) is $item[0] ?
> Do I need a custom function or is there something built in that I
> don't know about/can't find?
I think the function is called usort. You can pass a callback function
that in your case should compare the correct array fields of the "2D"
arrays that are passed.
If you have never worked with callbacks, look them up as well. They can
be plain functions, class methods or instance methods.
sorting does not necessarily have to take place in the database itself,
but as Oliver said, it can be more optimal to do it on the database
server than to do it in PHP. The database uses an index if possible, so
it is already sorted.
Best regards
[Back to original message]
|