PHP/Data Structure/array multisort — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:02, 26 мая 2010
array_multisort
<?php
$staff["givenname"][0] = "J";
$staff["givenname"][1] = "M";
$staff["givenname"][2] = "G";
$staff["surname"][1] = "C";
$staff["surname"][2] = "G";
$staff["surname"][3] = "E";
$res = array_multisort($staff["surname"],SORT_STRING,SORT_ASC,
$staff["givenname"],SORT_STRING,SORT_ASC);
print_r($staff);
?>
array_multisort for Array Keys with a Given Value
<?php
$clothes = array( "hats" => 75, "coats" => 32, "shoes" => 102);
$names = array_keys($clothes);
$items = array_values($clothes);
array_multisort($items, $names);
$num = count($clothes) - 1;
printf("<p>Most items: %s (%d); least items: %s (%d).</p>\n",$names[$num], $items[$num], $names[0], $items[0]);
?>