User Tools

Site Tools


inf:php:asort

Funkcja asort() sortuje tablicę z indeksami w postaci ciągów według zawartości:

        <?php
        $porn = array("Fast Lane to Malibu" => "2000",  "Testing the Limits" =>
            "1998", "I Like to Play Games" => "1995", "Lust Connection" =>
            "2005", "The Final Victim" => "2003");
 
        $ktory_film = current($porn);
        $ktory_rok = key($porn);
        echo "<h1>Lista nieposortowana</h1>";
 
        while(list($ktory_film, $ktory_rok) = each($porn)) {
            echo "<br>$ktory_rok - $ktory_film";
        }
 
        echo "<h1>Lista posortowana</h1>";
 
        asort($porn);
 
        while(list($ktory_film, $ktory_rok) = each($porn)) {
            echo "<br>$ktory_rok - $ktory_film";
        }
 
        ?>

a wynik to:

Lista nieposortowana

2000 - Fast Lane to Malibu
1998 - Testing the Limits
1995 - I Like to Play Games
2005 - Lust Connection
2003 - The Final Victim

Lista posortowana

1995 - I Like to Play Games
1998 - Testing the Limits
2000 - Fast Lane to Malibu
2003 - The Final Victim
2005 - Lust Connection
inf/php/asort.txt · Last modified: 2021/02/16 09:56 (external edit)