You are here: Re: sorting a 3d array? « PHP Programming Language « IT news, forums, messages
Re: sorting a 3d array?

Posted by Ciaran on 12/02/07 02:35

On Dec 2, 12:21 am, Chuck Anderson <websiteaddr...@seemy.sig> wrote:
> 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);
>

Cool solution there Chuck - best one so far by my reckoning! My select
statement is too complicated for me to sort results by date as Oliver
suggested - It's selecting various fields across multiple tables.
Besides the php solution has other advantages for my page design.
I'll try out the array_multisort tomorrow and let you know how I get
on.
Thanks for all replies,
Ciarán

 

Navigation:

[Reply to this 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

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