Funkce PHP uasort().
Příklad
Seřaďte prvky pole $arr podle hodnot pomocí uživatelsky definované porovnávací funkce:
<?php
function my_sort($a,$b)
{
if ($a==$b) return 0;
return ($a<$b)?-1:1;
}
$arr=array("a"=>4,"b"=>2,"c"=>8,"d"=>6);
uasort($arr,"my_sort");
?>
Definice a použití
Funkce uasort() třídí pole podle hodnot pomocí uživatelsky definované porovnávací funkce.
Tip: Použijte funkci uksort() k seřazení pole podle klíčů pomocí uživatelsky definované porovnávací funkce.
Syntax
uasort(array, myfunction)
Hodnoty parametrů
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
myfunction | Optional. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument |
Technické údaje
Návratová hodnota: | PRAVDA o úspěchu. NEPRAVDA při selhání |
---|---|
Verze PHP: | 4+ |
❮ PHP Array Reference