For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > August 2006 > #38635 [Opn->Bgs]: sort and it's similar commands discriminate agaisnt case.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #38635 [Opn->Bgs]: sort and it's similar commands discriminate agaisnt case.
hholzgra@php.net

2006-08-29, 4:02 am

ID: 38635
Updated by: hholzgra@php.net
Reported By: xconspirisist at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: Linux
PHP Version: Irrelevant
New Comment:

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, ', ');
?>


Previous Comments:
------------------------------------------------------------------------

[2006-08-29 00:36:42] 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


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=38635&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com