You are here: Re: Array « PHP Programming Language « IT news, forums, messages
Re: Array

Posted by Ewoud Dronkert on 11/26/05 18:14

Joe wrote:
> As I see it it can sort the values but doesn't keep the personid fixed to
> the salary.

Is that important? I don't know. I mean, where's the real data? He only
showed us the keys of a 2D array. Very weird to use salary as the 2nd key!
And, is there only one index value for each personid??

So, use uasort instead of usort:

function cmp($a, $b) {
list($k1,) = each($a);
list($k2,) = each($b);
return $k1 - $k2;
}
uasort($person, 'cmp');

Or:

$k = array_keys($person);
foreach ( $k as $i )
list($salary[$i],) = each($person[$i]);
asort($salary);

--
E. Dronkert

 

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

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