php / php/doc-en

array_unique with SORT_REGULAR flag does not always work as expected

Open
#1,463 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Category: Arrays enhancement Extension: standard
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

The following code:

<?php
print_r(array_unique(["100","100","25","15p100","25","25"], SORT_REGULAR));

Resulted in this output:

Array
(
    [0] => 100
    [2] => 25
    [3] => 15p100
    [4] => 25
)

But I expected this output instead:

Array
(
    [0] => 100
    [2] => 25
    [3] => 15p100
)

It happens because of the value "15p100", if I remove the letter "p" it works. It happens with any character not digit (example "15+100").

PHP Version

PHP 8.1.2

Operating System

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported array_unique example with SORT_REGULAR on PHP 8.1.2 and compare the observed output with the expected output in the issue. Locate the relevant array_unique documentation entry, then clarify the documented behavior once the discrepancy is understood; the issue is 330 days since its last comment.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.