php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5730 sort and rsort are not 'opposites'
Submitted: 2000-07-22 00:35 UTC Modified: 2000-07-23 11:03 UTC
From: the_jalal at yahoo dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.0 OS: Linux 2.3 SuSE 6.3
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: the_jalal at yahoo dot com
New email:
PHP Version: OS:

 

 [2000-07-22 00:35 UTC] the_jalal at yahoo dot com
sort an array and rsort an array should give the same order in reverse, the following does not:
------------
$a = array("0", "1", "01", "2");
sort($a);
while (list ($key, $value) = each ($a)) {
    echo "$key: $value\n";
}
echo "\n";
$a = array("0", "1", "01", "2");
rsort($a);
while (list ($key, $value) = each ($a)) {
    echo "$key: $value\n";
}
------------
gives the results:
0: 0
1: 01
2: 1
3: 2

0: 2
1: 01
2: 1
3: 0



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-23 11:03 UTC] stas at cvs dot php dot net
This is how it is meant to work. By default PHP sorts is
"numeric". If you need "string" sort, use sort($arr,SORT_STRING).
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 13 07:00:01 2026 UTC