You are here: Re: sort array « All PHP « IT news, forums, messages
Re: sort array

Posted by Paul on 10/16/07 10:00

"ZeldorBlat" <zeldorblat@gmail.com> schreef in bericht
news:1192478692.496334.152780@v29g2000prd.googlegroups.com...
> On Oct 15, 3:20 pm, "Paul" <piet...@xs4all.nl> wrote:
>> How can I sort a multi-dimensional array?
>> For instance:
>> a[Name], a[adress], a[number of messages].
>>
>> How to sort on the item of number of messages?
>>
>> Thanks for the help.
>
> Something like this (untested):
>
> usort($a, create_function('$a1,$a2', 'return $a1["number of messages"]
> - $a2["number of messages"];'));
>
Thanks. My solution:
usort ($a, "mysort");
function mysort ($a, $b) {
if ($a['number of messages']<$b['number of messages']) return -1;
else if ($a['number of messages']>$b['number of messages']) return 1;
return 0;
}

 

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

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