在php中为捷克语排序数据数组结构 - 正确的数字排序

Original question: url

Sorting for Czech language is working now, but for numbers not. For example for this array:

$data = array(
 'items' => array(
    0 => array('city' => 'Praha 10'),
    1 => array('city' => 'Praha 2'),
    2 => array('city' => 'Praha 1'),
    3 => array('city' => 'Cheb'),
    4 => array('city' => 'České budějovice'),
    5 => array('city' => 'Šatov')
  ),
);



$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body, true )['data']['items'];
usort($data,
  function($a,$b) {
    $coll = collator_create( 'cs_CZ' );
    $aSortKey = collator_get_sort_key($coll, $a['city']);
    $bSortKey = collator_get_sort_key($coll, $b['city']);
    return $aSortKey >= $bSortKey;
  ;}
 );

Result will be: Cheb, České Budějovice, Praha 1, Praha 10, Praha 2, Šatov.

But correct should be: Cheb, České Budějovice, Praha 1, Praha 2, Praha 10, Šatov.

So smaller number like 2 must be before 10 or higher.

Did you try natsort instead of your usort?

In PHP, natural sort would handle this easily:

Here is the official link how to do this: php.net natural sort

Standard sorting:

Array
(
    [3] => img1.png
    [1] => img10.png
    [0] => img12.png
    [2] => img2.png
)

Natural order sorting:

Array
(
    [3] => img1.png
    [2] => img2.png
    [1] => img10.png
    [0] => img12.png
)