You are here: Re: array multisort question « PHP Programming Language « IT news, forums, messages
Re: array multisort question

Posted by Rik on 08/23/06 10:42

annmartinson@gmail.com wrote:
> No idea why this works, but I do appreciate it very much. plugged it
> in, works like a charm. thanks!!

Well for future reference, you may need another sort, so a short
explanation:
usort($array,'function_name');

function_name is the custom name of a function to sort by. This function
will get 2 variables to compare, $a and $b, which are 2 values from your
array, so in this case:

$a = array('id'=>1,'name'=>'fire,'value'=>0);
Likewise for b.

This function will have to return either:
0 when sorting should return equals.
-1 when $a should go before $b
1 when $a should come after $b

Now we only want to sort on the 'value' key, so we in the function we only
compare the 'value' key of 'a' and 'b'. In normal sorting, the whole array
$a and $b are compared.

Grtz,
--
Rik Wasmus

 

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

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