<?php
//The sort() function sorts the values of an array in ascending alphabetical/numerical order.
$hawaii = array("Hawai'i", "Kauai", "Maui", "Oahu", "Moloka'i", "Lana'i");
sort($hawaii);
print_r($hawaii);
//The rsort() function sort the values of an array in descending alphabetical/numerical order.
rsort($hawaii);
print_r($hawaii);
//The asort() function sorts an associative array, by its values, in ascending alphabetical/numerical order.
$caribbean = array("bahamas"=>"New Providence", "french west indies"=>"Martinique", "british west indies"=>"Turks & Caicos Islands");
asort($caribbean);
print_r($caribbean);
//The ksort() function sorts an associative array, by its keys, in ascending alphabetical/numerical order.
ksort($caribbean);
print_r($caribbean);
//The arsort() function sorts an associative array, by its values, in descending alphabetical/numerical order.
arsort($caribbean);
print_r($caribbean);
//The krsort() function sorts an associative array, by its keys in descending alphabetical/numerical order.
krsort($caribbean);
print_r($caribbean);
?>
Array
(
[0] => Hawai'i
[1] => Kauai
[2] => Lana'i
[3] => Maui
[4] => Moloka'i
[5] => Oahu
)
Array
(
[0] => Oahu
[1] => Moloka'i
[2] => Maui
[3] => Lana'i
[4] => Kauai
[5] => Hawai'i
)
Array
(
[french west indies] => Martinique
[bahamas] => New Providence
[british west indies] => Turks & Caicos Islands
)
Array
(
[bahamas] => New Providence
[british west indies] => Turks & Caicos Islands
[french west indies] => Martinique
)
Array
(
[british west indies] => Turks & Caicos Islands
[bahamas] => New Providence
[french west indies] => Martinique
)
Array
(
[french west indies] => Martinique
[british west indies] => Turks & Caicos Islands
[bahamas] => New Providence
)