#26412 [Com]: natsort ignores extra white space
ID: 26412
Comment by: jpatrin at pnicorp dot com
Reported By: phpbug at reuben dot com
Status: Bogus
Bug Type: Arrays related
Operating System: Mac OS X
PHP Version: 4.3.3
New Comment:
If you would actually look at the bug, you'd notice that "a a" id
sortes as before "a a", which is inconsistent with the sorting of "a
b" and "a b".
Previous Comments:
------------------------------------------------------------------------
[2003-11-25 15:40:30] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
' ' is 10 and 'b' is 98, make your own conclustions.
------------------------------------------------------------------------
[2003-11-25 14:02:05] phpbug at reuben dot com
Description:
------------
natsort (and related functions like strnatcmp) appear to
collapse all white space chars into just one space, so
that 'a a' sorts at the same level as 'a a' (so the
order of the returned sort is not determined), while it
should sort one before the other (which one is more
"natural" is up for discussion, but it shouldn't
randomly return one or the
other).
Reproduce code:
---------------
$array = array('a b','a a','a a','aa','a
b','ab');
natsort($array);
echo "<pre>";
foreach ($array as $val)
echo "$val\n";
echo "</pre>";
Expected result:
----------------
Should print:
aa
ab
a a
a b
a a
a b
-OR-
aa
a a
a a
ab
a b
a b
Actual result:
--------------
Actually prints (changes order if you change order in
array definition):
aa
a a
a a
ab
a b
a b
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26412&edit=1
Thread (3 messages)