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

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

 

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

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