PHP ksort()の結果がおかしいことがある

`ksort()`は連想配列をキーでソートする関数ですが、並び順の規則がどうこうという以前の順序の乱れが起こることがあるようです。

条件がいまひとつはっきり分かりませんが、なんとなく

- 連想配列の各キーが半角1文字
- '0'をキーとする要素がある
- ある程度の要素数

辺りが関係ありそうな感じでしょうか。

**テストスクリプト**

~~~php:test.php
<?php
foreach([
    'abcdefghijklmnopqrstuvwxyz01',
    'abcdefghijklmnopqrstuvwxyz0_',
    'abcdefghijklmnopqrstuvwxyz1_',
    'abcdefghijklmn01',
    'abcdefghijklmno01',
    'ABCDEFGH012345678',
    'ABCDEFGH123456789',
] as $keys) {
        // 連想配列作成
        $arr = [];
        foreach(str_split($keys) as $v) {
            $arr[$v] = 0;
        }

        // 初期状態の並び表示
        echo "---------------- \n";
        echo implode('', array_keys($arr)). "\n\n";

        // ksort()を通したあとの並びを何度か確認
        for($i = 0; $i < 4; $i++) {
            ksort($arr);
            echo implode('', array_keys($arr)). "\n";
        }

        print "\n";
}
~~~

**結果**

~~~plain
% php -v
PHP 7.3.18 (cli) (built: May 17 2020 11:11:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.18, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.18, Copyright (c) 1999-2018, by Zend Technologies

% php test.php
----------------
abcdefghijklmnopqrstuvwxyz01

a0bcdefghijklmnopqrstuvwxyz1
abcdefghijklmn0opqrstuvwxyz1
aopqrstuvwxyz0bcdefghijklmn1
a0bcdefghijklmnopqrstuvwxyz1

----------------
abcdefghijklmnopqrstuvwxyz0_

_0abcdefghijklmnopqrstuvwxyz
_abcdefghijklm0nopqrstuvwxyz
_nopqrstuvwxy0abcdefghijklmz
_0abcdefghijklmnopqrstuvwxyz

----------------
abcdefghijklmnopqrstuvwxyz1_

_abcdefghijklmnopqrstuvwxyz1
_abcdefghijklmnopqrstuvwxyz1
_abcdefghijklmnopqrstuvwxyz1
_abcdefghijklmnopqrstuvwxyz1

----------------
abcdefghijklmn01

abcdefghijklmn01
abcdefghijklmn01
abcdefghijklmn01
abcdefghijklmn01

----------------
abcdefghijklmno01

a0bcdefghijklmno1
abcdefgh0ijklmno1
aijklmno0bcdefgh1
abcdefgh0ijklmno1

----------------
ABCDEFGH012345678

ABGH0CDEF12345678
ABCDEF0GH12345678
ABCDEFGH012345678
ABGH0CDEF12345678

----------------
ABCDEFGH123456789

ABCDEFGH123456789
ABCDEFGH123456789
ABCDEFGH123456789
ABCDEFGH123456789

% /home/rs/php/5.6/bin/php -v
PHP 5.6.40 (cli) (built: Mar  9 2020 09:28:17)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

% /home/rs/php/5.6/bin/php test.php
----------------
abcdefghijklmnopqrstuvwxyz01

abcdefghi0jklmnopqrstuvwxyz1
abcdefghijklm0nopqrstuvwxyz1
nopqrstuvwxyz0abcdefghijklm1
abcdefghijklm0nopqrstuvwxyz1

----------------
abcdefghijklmnopqrstuvwxyz0_

_abcdefgh0ijklmnopqrstuvwxyz
_abcdefghijkl0mnopqrstuvwxyz
mnopqrstuvwxyz0_abcdefghijkl
_abcdefghijklmnopqrstuvwxyz0

----------------
abcdefghijklmnopqrstuvwxyz1_

_abcdefghijklmnopqrstuvwxyz1
_abcdefghijklmnopqrstuvwxyz1
_abcdefghijklmnopqrstuvwxyz1
_abcdefghijklmnopqrstuvwxyz1

----------------
abcdefghijklmn01

abcde0fghijklmn1
abcdefg0hijklmn1
hijklmn0abcdefg1
abcdefg0hijklmn1

----------------
abcdefghijklmno01

abcdef0ghijklmno1
abcdefgh0ijklmno1
aijklmno0bcdefgh1
abcdefgh0ijklmno1

----------------
ABCDEFGH012345678

AFGH0BCDE12345678
ABCDEF0GH12345678
ABCDEFGH012345678
AFGH0BCDE12345678

----------------
ABCDEFGH123456789

ABCDEFGH123456789
ABCDEFGH123456789
ABCDEFGH123456789
ABCDEFGH123456789
~~~