Reply to Re: sorting a 3d array?

Your name:

Reply:


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.
***********************************

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация