Sorts an array in ascending order by key.
ksort() orders the elements by key, rather than the value of the elements. The optional sort_type parameter specifies whether the elements should be sorted as strings or numerically. If the array was sorted successfully, TRUE is returned.
<pre>
<?php
$cities = array(
"Miami" => "Florida",
"New Orleans" => "Louisiana",
"Los Angeles" => "California",
"Atlanta" => "Georgia",
"Memphis" => "Tennessee");
ksort($cities);
print_r($cities);
?>
</pre>
Array
(
[Atlanta] => Georgia
[Los Angeles] => California
[Memphis] => Tennessee
[Miami] => Florida
[New Orleans] => Louisiana
)
An array with cities as keys and states as values is sorted with ksort().