|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-29 00:36 UTC] xconspirisist at gmail dot com
Description:
------------
I assume this is a documentation problem, as I hardly think that this could possibly be the intended output.
If you use lower case letters at the beginning of strings that are part of an array, and then use the sort() function on the array, the sort() function will take preference over upper case letters.
Reproduce code:
---------------
<?php
$a = array('apples', 'Banannas', 'Carrots' );
sort($a);
echo implode($a, ', ');
?>
Expected result:
----------------
apples, Banannas, Carrots
Actual result:
--------------
Banannas, Carrots, apples
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Jan 29 03:00:01 2026 UTC |
This is definetly the intended resut as all PHP string comparisons are case sensitive (using strcmp() for comparison) and as the lower case letters have higher character codes than the lower case ones (in all common character sets like ASCII, iso-8859-x, Unicode) For case insensitive sorting you need to explicitly specify the comparison function in a user defined sort: <?php $a = array('apples', 'Banannas', 'Carrots' ); usort($a, "strcasecmp"); echo implode($a, ', '); ?>