ksort() does not return a sorted array, but rather sorts the array in place. After calling ksort($array) contents of $array will be sorted. The function returns whether the sort was successful or not.
Example:
$array = array(1 => 1, 20 => 1, 5 => 1); echo "Before ksort():\n"; print_r($array); if (ksort($array)) { echo "ksort() completed successfully.\n"; } echo "After ksort():\n"; print_r($array);
The above prints:
Before ksort(): Array ( [1] => 1 [20] => 1 [5] => 1 ) ksort() completed successfully. After ksort(): Array ( [1] => 1 [5] => 1 [20] => 1 )
You should not check the return value of ksort() , though, since ksort() can only fail if it cannot even fail. Therefore, the function will either return true or the script will die, in which case the return value does not matter (it will always be true ).
source share