ID: 40334
Updated by: [EMAIL PROTECTED]
Reported By: den4b at mail dot ru
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Windows XP SP2
PHP Version: 5.2.0
New Comment:
1 coming before 0?
No, that's definitely not the result expected.
0 will always come before 1.
Previous Comments:
------------------------------------------------------------------------
[2007-02-03 01:11:28] den4b at mail dot ru
Reproduce code:
---------------
$a = array('a 02', 'a 1', 'a 02000', 'a 03');
natsort($a);
print_r($a);
Result (Incorrect):
--------------
Array
(
[0] => a 02
[2] => a 02000
[3] => a 03
[1] => a 1
)
------------------------------------------------------------------------
[2007-02-03 01:05:59] den4b at mail dot ru
Re-opening this bug.
------------------------------------------------------------------------
[2007-02-03 01:03:35] den4b at mail dot ru
They are strings, that's why they are surrounded with ''. If you are
still in doubt - try inserting any string infront of every element,
you'll still see the very same effect!
The natural-order-aware algorithm that is used for comparing strings
has problems. It was addopted from
http://sourcefrog.net/projects/natsort/ - I tested it, and it produced
the very same bogus results!
------------------------------------------------------------------------
[2007-02-02 23:09:25] [EMAIL PROTECTED]
These numbers are called octal.
http://www.php.net/manual/en/language.types.integer.php
------------------------------------------------------------------------
[2007-02-02 22:00:49] den4b at mail dot ru
Description:
------------
natsort() does not work for some numbers...
Reproduce code:
---------------
$a = array('02', '1', '02000', '03');
natsort($a);
print_r($a);
Expected result:
----------------
Array
(
[1] => 1
[0] => 02
[3] => 03
[2] => 02000
)
Actual result:
--------------
Array
(
[0] => 02
[2] => 02000
[3] => 03
[1] => 1
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40334&edit=1