Warning: file_put_contents(): Only -1 of 44 bytes written, possibly out of free disk space in /var/www/html/index.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:3) in /var/www/html/cache.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:3) in /var/www/html/cache.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:3) in /var/www/html/cache.php on line 25
asort Manuál PHP Předcházející Další (PHP 3, 4, 5) asort -- Třídit pole se zachováním indexů Popis bool ( array &array [, int sort_flags] ) asort() třídí tak, že ...
Forum und email
asort

asort

(PHP 3, PHP 4, PHP 5)

asort -- Třídit pole se zachováním indexů

Popis

bool asort ( array &array [, int sort_flags] )

asort() třídí pole tak, že si indexy zachovají corelace s prvky, se kterými jsou spojeny. To je užitečné hlavně při třídění asociativních polí, u kterých je pořadí prvků signifikantní.

Příklad 1. Ukázka asort()

$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
asort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
    echo "$key = $val\n";
}

Tato ukázka zobrazí:

fruits[c] = apple
fruits[b] = banana
fruits[d] = lemon
fruits[a] = orange

Ovoce bylo setříděno podle abecedy a indexy spojené s jednotlivými prvky byly zachovány.

Chování třídění můžete upravit pomocí volitelného argumentu sort_flags, detaily viz sort().

Viz také: arsort(), rsort(), ksort() a sort().