Bug #74672 [Opn]: natsort() not ordering as expected
| From: | php-bugs-2014-08 at dotancohen dot com | Date: | Tue, 30 May 2017 07:04:09 +0000 |
| Subject: | Bug #74672 [Opn]: natsort() not ordering as expected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209299@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74672&edit=1
ID: 74672
User updated by: php-bugs-2014-08 at dotancohen dot com
Reported by: php-bugs-2014-08 at dotancohen dot com
-Summary: var_export does not export a parsable string
representation of stdClass objects
+Summary: natsort() not ordering as expected
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Linux melancholy 3.13.0-34-gener
PHP Version: 7.1.5
Block user comment: N
Private report: N
New Comment:
Note that the issue is visible when decimals or 0 padding is used in the numeric part of the strings
to be sorted.
Previous Comments:
------------------------------------------------------------------------
[2017-05-30 06:53:16] php-bugs-2014-08 at dotancohen dot com
Description:
------------
The order of elements in the array sorted by natsort() is not as expected by the function's
name and description.
Test script:
---------------
<?php
$a = array('13.59', '14.6', '14.19');
natsort($a);
var_dump($a);
$b = array('img0120.jpg','img0.png', 'img0012.png',
'img10.png', 'img2.png', 'img1.png', 'img3.png');
natsort($b);
var_dump($b);
Expected result:
----------------
array(3) {
[0]=>
string(5) "13.59"
[1]=>
string(5) "14.19"
[2]=>
string(4) "14.6"
}
array(7) {
[0]=>
string(8) "img0.png"
[1]=>
string(8) "img1.png"
[2]=>
string(8) "img2.png"
[3]=>
string(8) "img3.png"
[4]=>
string(9) "img10.png"
[5]=>
string(11) "img0012.png"
[6]=>
string(11) "img0120.jpg"
}
Actual result:
--------------
array(3) {
[0]=>
string(5) "13.59"
[1]=>
string(4) "14.6"
[2]=>
string(5) "14.19"
}
array(7) {
[1]=>
string(8) "img0.png"
[2]=>
string(11) "img0012.png"
[0]=>
string(11) "img0120.jpg"
[5]=>
string(8) "img1.png"
[4]=>
string(8) "img2.png"
[6]=>
string(8) "img3.png"
[3]=>
string(9) "img10.png"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74672&edit=1