php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5722 sort fails
Submitted: 2000-07-21 16:05 UTC Modified: 2000-07-21 16:09 UTC
From: biancardi at bware dot it Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.1pl2 OS: SunOS sundev 5.7 Generic_106541-
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: biancardi at bware dot it
New email:
PHP Version: OS:

 

 [2000-07-21 16:05 UTC] biancardi at bware dot it
sort() sorts strings numerically. The following program
behaves differently on php4 (solaris) and php3 (linux):
<?
        $a = array("0", "1", "2", "01", "02", "03", "23","044");
        sort($a);
        while (list ($key, $value) = each ($a)) {
                echo "$key: $value\n";
        }
?>

php4.0.1.pl1 (on Solaris) results:
0: 0
1: 1
2: 01
3: 2
4: 02
5: 03
6: 23
7: 044

php3 (on Linux) results:
0: 0
1: 01
2: 02
3: 03
4: 044
5: 1
6: 2
7: 23


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-21 16:09 UTC] andrei at cvs dot php dot net
Regular sort function tries to convert strings to numbers before sorting.
You can control the sort type by passing an optional argument
to sorting functions:

sort($array, SORT_REGULAR);
sort($array, SORT_NUMERIC);
sort($array, SORT_STRING);
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC