Skip to content

[intl] Weird numeric sort in Collator #18566

Open
@arokettu

Description

@arokettu

Description

The following code:

<?php

$arr = [
    '2023-02-04 14:00:00',
    '2023-01-08 12:00:00',
    '2023-01-03 12:00:00',
    '2023-01-03 12:00:00',
    '2021-01-03 12:00:00',
    '2023-01-05 14:00:00',
    '2024-01-03 12:00:00',
    '2023-01-03 12:00:00',
];

$coll = Collator::create('de');

$coll->asort($arr, Collator::SORT_REGULAR);

echo json_encode($arr, JSON_PRETTY_PRINT);

Resulted in this output:

{
    "4": "2021-01-03 12:00:00",
    "0": "2023-02-04 14:00:00",
    "1": "2023-01-08 12:00:00",
    "2": "2023-01-03 12:00:00",
    "3": "2023-01-03 12:00:00",
    "5": "2023-01-05 14:00:00",
    "7": "2023-01-03 12:00:00",
    "6": "2024-01-03 12:00:00"
}%

But I expected this output instead:

{
    "4": "2021-01-03 12:00:00",
    "2": "2023-01-03 12:00:00",
    "3": "2023-01-03 12:00:00",
    "7": "2023-01-03 12:00:00",
    "5": "2023-01-05 14:00:00",
    "1": "2023-01-08 12:00:00",
    "0": "2023-02-04 14:00:00",
    "6": "2024-01-03 12:00:00"
}

PHP Version

Since the dawn of time up to 8.4.7 apparently introduced in PHP6(!)

https://3v4l.org/fVcRj

Operating System

any

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions