1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 09:12:14 +01:00
Files
archived-php-src/ext/standard/tests/array/usort_stability.phpt
Nikita Popov e12b9df05d Make sorting stable
Make user-exposed sorts stable, by storing the position of elements
in the original array, and using those positions as a fallback
comparison criterion. The base sort is still hybrid q/insert.

The use of true/false comparison functions is deprecated (but still
supported) and should be replaced by -1/0/1 comparison functions,
driven by the <=> operator.

RFC: https://wiki.php.net/rfc/stable_sorting

Closes GH-5236.
2020-06-25 10:49:34 +02:00

16 lines
212 B
PHP

--TEST--
usort() is stable
--FILE--
<?php
$array = range(0, 10000);
usort($array, function($a, $b) {
// Everything is equal!
return 0;
});
var_dump($array === range(0, 10000));
?>
--EXPECT--
bool(true)