#44929 [Asn->Csd]: [PATCH] natsort and natcasesort fail if numbers in strings prepended by 0
| From: | rasmus@php.net | Date: | Sat, 02 May 2009 20:29:16 +0000 |
| Subject: | #44929 [Asn->Csd]: [PATCH] natsort and natcasesort fail if numbers in strings prepended by 0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136665@lists.php.net to get a copy of this message | ||
ID: 44929
Updated by: rasmus@php.net
Reported By: kae at verens dot com
-Status: Assigned
+Status: Closed
Bug Type: Arrays related
Operating System: *
PHP Version: 5.*, 6CVS (2009-05-02)
Assigned To: rasmus
New Comment:
Yeah, we talked about that on internals. It's pretty much an either/or
thing. If you want numeric sorting, sort it numerically. This is
natcasesort and is more intended for filenames and such. So this is
expected.
Previous Comments:
------------------------------------------------------------------------
[2009-05-02 18:59:02] jani@php.net
This fails now (in both 32bit and 64bit systems):
# php -r '$a = array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 33);
natcasesort($a); var_dump($a);'
array(9) {
[2]=>
float(-0.01)
[7]=>
float(-0.9)
[3]=>
int(-1)
[4]=>
int(0)
[0]=>
float(0.0001)
[5]=>
float(0.09)
[1]=>
float(0.0021)
[6]=>
int(2)
[8]=>
int(33)
}
------------------------------------------------------------------------
[2009-04-08 18:11:28] rasmus@php.net
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Fixed in CVS
------------------------------------------------------------------------
[2009-04-08 15:17:37] bax_70 at hotmail dot com
Excuseme bad example
the right one
$a[0]="00001";
$a[1]="00008";
$a[2]="00005";
$a[3]="000011";
$a[4]="00003";
$a[5]="000014";
natsort($a);
print_r($a);
Array ( [0] => 00001 [3] => 000011 [5] => 000014 [4] => 00003 [2] =>
00005 [1] => 00008 )
------------------------------------------------------------------------
[2009-04-08 14:35:44] bax_70 at hotmail dot com
Bad result.
$a[0]=00001;
$a[1]=00008;
$a[2]=00005;
$a[3]=000011;
$a[4]=00003;
$a[5]=000014;
natsort($a);
print_r($a);
Array ( [1] => 0 [0] => 1 [4] => 3 [2] => 5 [3] => 9 [5] => 12 )
------------------------------------------------------------------------
[2008-08-27 08:41:25] rasmus@php.net
Checking this further, this patch messes up the order of "0" in an
array that contains negative values like "-123", so it still needs some
work.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/44929
--
Edit this bug report at http://bugs.php.net/?id=44929&edit=1