php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16942 natsort broken
Submitted: 2002-05-01 07:01 UTC Modified: 2002-05-01 07:13 UTC
From: blazeroni at yahoo dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.1.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: blazeroni at yahoo dot com
New email:
PHP Version: OS:

 

 [2002-05-01 07:01 UTC] blazeroni at yahoo dot com
There's something wrong with the natsort() algorithm.  I sorted an array and echo'ed it out using the following code:


-------------------------------------------------
$array = array("d02", "d3", "j_j", "d04", "d03");
natsort($array);

for ($i=0; $array[$i]; $i++) {
    echo "[".$i."]: ".$array[$i]."\n";
}
-------------------------------------------------

Here's what it spit out:

------------
[0]: d02
[1]: d3 
[2]: j_j 
[3]: d04 
[4]: d03
------------

I'm not sure what kind of ordering it used, but it doesn't seem to follow any pattern that I know of.  =)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-01 07:13 UTC] derick@php.net
natsort() retains the keys, use foreach ($array as $value) { echo $value."\n"; }

Derick
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 21 21:03:32 2021 UTC