php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #6512 sort() Does not sort stings as expected
Submitted: 2000-09-03 07:12 UTC Modified: 2010-08-07 01:43 UTC
From: jmoore@php.net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.2 OS: *
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: jmoore@php.net
New email:
PHP Version: OS:

 

 [2000-09-03 07:12 UTC] jmoore@php.net
When using sort, it sorts by ASCII code and not alphabetically, this might be what was intended but the function does not behave as might be expected, take the following example:

<?php
$test = array("AA","AC","AR","AJ","Ab");
asort($test);
var_dump($test);
?>

Does not ourput

AA,Ab,AC,AJ,AR

But infact

AA,AC,AJ,AR,Ab

Now this is due to Ascii Char codes. Perhaps a warning should be added to the manual if this behaviour stays the same.

James

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-03 07:21 UTC] waldschrott@php.net
I?d vote for adding another option to all sorting functions,
like SORT_CASED, maybe the bit way

asort($x,SORT_STRING|SORT_CASED)

 [2000-09-03 08:26 UTC] jmoore@php.net
natcasesort() and natsort() do this, I will add a see also for natcasesort to sort.
 [2000-09-03 08:31 UTC] waldschrott@php.net
well, natcasesort() does this for natural sorting, but
regular/string/numeric sorting can?t be sorted cased...
not sure if it should be closed...
 [2000-09-03 08:35 UTC] jmoore@php.net
OK Chaning to feature/change request and reopening. (The function isnt really misbehaving...)
 [2010-08-07 01:43 UTC] johannes@php.net
-Status: Analyzed +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-08-07 01:43 UTC] johannes@php.net
Expected behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 22:01:30 2024 UTC