Reply to Re: Sorting arrays

Your name:

Reply:


Posted by Janwillem Borleffs on 05/21/06 15:43

Paul Lautman wrote:
> Can you give me an example of where usort and uasort give different
> outputs and how uksort would be used?
>

function cmp($a, $b) {
if ($a == $b) return 0;
return $a < $b ? -1 : 1;
}

$array = array('b' => 200, 'a' => 50, 'A' => 100);
$usort = $uasort = $uksort = $array;

print 'original array:<br>';
print_r($array);

print '<hr>usort: sorted by value, keys are not preserved:<br>';
usort($usort, 'cmp');
print_r($usort);

print '<hr>uasort: sorted by value, keys are preserved:<br>';
uasort($uasort, 'cmp');
print_r($uasort);

print '<hr>uksort: sorted by key;<br>';
print '"A" put before "a" because of its lower ASCII value:<br>';
uksort($uksort, 'cmp');
print_r($uksort);


JW

[Back to original 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

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