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
 [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

 [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

 [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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC