Closed
Description
Description
The behavior of the string and number comparison operators has been changed since php 8, but ksort
and krsort
functions still use the old rules.
It leads to inconsistent situations, when after ksort
the first key is greater than some of the next ones by according to the basic comparison operators.
The following code:
<?php
$array = ["600" => 0, "aaa" => 1];
ksort($array, SORT_REGULAR);
var_dump($array);
var_dump(array_key_first($array) <=> array_key_last($array));
Resulted in this output:
array(2) {
["aaa"]=>
int(1)
[600]=>
int(0)
}
int(1)
But I expected this output instead:
array(2) {
[600]=>
int(0)
["aaa"]=>
int(1)
}
int(-1)
PHP Version
PHP 8.0
Operating System
No response