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
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:
23 - 6 = ?
Subscribe to this entry?

 
 [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: Thu Apr 25 09:01:29 2024 UTC