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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 - 13 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 19:01:33 2024 UTC