|
Posted by Chuck Anderson on 12/02/07 00:21
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?
>
> Thanks in advance
> Ciarán
>
It's built in. array_multisort.
(I may not be using this function the best way, and if I'm missing a
simpler way to do this then hopefully someone will point that out. This
function does somewhat baffle me, but by trial and error I have found
that this works.)
While building this structure - create the $date array:
$item[0]['title']
$item[0]['content']
$item[0]['date']
$date[0] = $item[0]['date']
$item[1]['title']
$item[1]['content']
$item[1]['date']
$date[1] = $item[1]['date']
etc...
Then this will work
array_multisort($date, SORT_DESC, $item);
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************
Navigation:
[Reply to this message]
|