PHP's sort functions compare values loosely, so 1 and "1" look the same, and so do null and false. This RFC from Jason Marble adds a SORT_STRICT flag that compares values without type juggling.

Today, if you want strict sorting or strict unique values, you have to write your own usort() callback. The RFC calls that verbose, slower and error-prone.

Show me

With array_unique(), loose comparison throws away values that only look alike:

$values = [0, "0", null, false, ""];

array_unique($values, SORT_REGULAR);
// 2 values left: 0 and ""

array_unique($values, SORT_STRICT);
// all 5 values kept

With sort(), values are grouped by type first:

$values = ["1", true, 1, null, 1.0];

sort($values, SORT_STRICT);
// null, true, 1, 1.0, "1"

How it works

SORT_STRICT compares in two steps. First it checks the type, using this order:

NULL < Bool < Int < Float < String < Array < Object < Resource

If the types differ, the type order decides. If they match, it compares the values: numbers compare numerically, and strings compare byte by byte, like strcmp(). That means "10" sorts before "2", and "1e3" isn't equal to "1000". Arrays and objects apply the same strict rules to their contents.

The flag works with:

  • sort() and rsort()
  • asort() and arsort()
  • ksort() and krsort()
  • array_multisort()
  • array_unique()

The RFC also floats a later idea: array_diff() and array_intersect() could get a flags argument so they could use SORT_STRICT too. That isn't part of this RFC.

What it means for existing code

Nothing breaks. The RFC adds a new constant, and existing flags behave the same way. IDEs and static analyzers will need to learn about SORT_STRICT.

Where it stands

The RFC is a draft, first written on November 29, 2025. It has a pull request, but the patch is still a work in progress and no vote has been held. It would need a two-thirds majority to pass.