The first thing that I didn't find in description it's that this function return results from MIN value to MAX value, ex: [-5=>'', 0=>'', 5=>'' ]
Also you should know that by default, it has correct sorting for keys that represented as string but has a number as value, ex: ['-5'=>'', '0'=>'', '5'=>'' ]
Few examples with results:
-----------------------------------------
DESCRIPTION: Keys are numbers + default flag (SORT_REGULAR)
$arr = [
-5 => 'minus five',
0 => 'zero',
1 => 'one',
2 => 'two',
100 => 'hundred',
];
ksort($arr);
print_r($arr);
RESULT:
Array
(
[-5] => minus five
[0] => zero
[1] => one
[2] => two
[100] => hundred
)
-----------------------------------------
DESCRIPTION: Keys are string numbers + default flag (SORT_REGULAR)
$arr = [
'-5' => 'minus five',
'0' => 'zero',
'1' => 'one',
'2' => 'two',
'100' => 'hundred',
];
ksort($arr);
print_r($arr);
RESULT:
Array
(
[-5] => minus five
[0] => zero
[1] => one
[2] => two
[100] => hundred
)
-----------------------------------------
DESCRIPTION: Keys are string numbers + SORT_STRING flag
$arr = [
'-5' => 'minus five',
'0' => 'zero',
'1' => 'one',
'2' => 'two',
'100' => 'hundred',
];
ksort($arr, SORT_STRING);
print_r($arr);
RESULT:
Array
(
[-5] => minus five
[0] => zero
[1] => one
[100] => hundred
[2] => two
)
-----------------------------------------
DESCRIPTION: Keys are string numbers + SORT_NUMERIC flag
$arr = [
'-5' => 'minus five',
'0' => 'zero',
'1' => 'one',
'2' => 'two',
'100' => 'hundred',
];
ksort($arr, SORT_NUMERIC);
print_r($arr);
RESULT:
Array
(
[-5] => minus five
[0] => zero
[1] => one
[2] => two
[100] => hundred
)