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

Posted by Michael Fesser on 10/16/07 18:05

..oO(Paul)

>"ZeldorBlat" <zeldorblat@gmail.com> schreef in bericht
>news:1192478692.496334.152780@v29g2000prd.googlegroups.com...
>>
>> 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;
>}

JFTR: I would drop the if-else and simply return the difference between
both values as in ZeldorBlat's function. The comparison function doesn't
necessarily have to return exactly -1, 0 or 1, the return value just has
to be lower than, equal to or greater than zero.

Micha

 

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

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