Bug #76662 [NEW]: Issue sorting when values are equal
| From: | panin dot alexei at gmail dot com | Date: | Wed, 25 Jul 2018 08:01:17 +0000 |
| Subject: | Bug #76662 [NEW]: Issue sorting when values are equal | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-216440@lists.php.net to get a copy of this message | ||
From: panin dot alexei at gmail dot com
Operating system: OSX and UBUNTU
PHP version: 7.0.31
Package: *General Issues
Bug Type: Bug
Bug description:Issue sorting when values are equal
Description:
------------
---
From manual page: http://www.php.net/function.usort
---
Even when values are equal, they are mixed. The resulting / sorted array
should be identical with initial array, it;s not the case.
Test script:
---------------
<?php
$array = [
["1", 1],
["2", 1],
["3", 1],
["4", 1],
["5", 1],
["6", 1],
["7", 1],
["8", 1],
["9", 1],
["10", 1],
["11", 1],
["12", 1],
["13", 1],
["14", 1],
["15", 1],
["16", 1],
["17", 1],
["18", 1],
["19", 1],
["20", 1],
["21", 1],
["22", 1],
["23", 1],
["24", 1],
["25", 1],
["26", 1],
["27", 1],
["28", 1],
["29", 1],
["30", 1],
["31", 1],
["32", 1],
["33", 1],
["34", 1],
["35", 1],
["36", 1]
];
usort($array, function($a, $b){
return $a[1] <=> $b[1];
});
print_r($array);
Expected result:
----------------
array should bot be altered
Actual result:
--------------
array is sorted
--
Edit bug report at https://bugs.php.net/bug.php?id=76662&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76662&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76662&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76662&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76662&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76662&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76662&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76662&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76662&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76662&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76662&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76662&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76662&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76662&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76662&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76662&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76662&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76662&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76662&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76662&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76662&r=mysqlcfg