#19850 [Csd->Opn]: sorting a String case-sensitive fails

From: Date: Sun, 17 Nov 2002 13:01:13 +0000
Subject: #19850 [Csd->Opn]: sorting a String case-sensitive fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-25090@lists.php.net to get a copy of this message
 ID:               19850
 User updated by:  akorthaus@web.de
 Reported By:      akorthaus@web.de
-Status:           Closed
+Status:           Open
 Bug Type:         Arrays related
 Operating System: Linux + Windows
 PHP Version:      4CVS-2002-10-10
 New Comment:

Sorry that I open it again, but what should be the sense of sorting an
array like

Array
(
[0] => A
[1] => a
[2] => AA
[3] => b
[4] => B
[5] => BB
)

usort($test, 'strcasecmp'); 

should sort case-sensitive, that means a,A, b,B, c,C... but what is
A,a, b,B??? There is no logical algorithm to sort this way. What is the
next? c,C or C,c? How can I get a,A, b,B, c,C..., means _real_
case-sensitive?


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

[2002-10-27 19:56:59] sterling@php.net

it works for me:

Array
(
[0] => A
[1] => a
[2] => AA
[3] => b
[4] => B
[5] => BB
)

Which is exactly what you should get... and the algorithm is platform
independent in CVS....

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

[2002-10-10 10:41:32] akorthaus@web.de

I tried the following script to sort an Array case-sensitive:


<?php
$test = array("B",
              "a",
              "b",
              "A",
              "BB",
              "AA");
usort($test, 'strcasecmp');
print_r($test);
?>

What I expected to get was:

Array
(
    [0] => A
    [1] => a
    [2] => AA
    [3] => B
    [4] => b
    [5] => BB
)

What I got on Win2000/PHP 4.2.4-dev was:

Array
(
    [0] => A
    [1] => a
    [2] => AA
    [3] => b
    [4] => B
    [5] => BB
)

and using Linux with PHP 4.1.2 I got

Array
(
    [0] => a
    [1] => A
    [2] => AA
    [3] => B
    [4] => b
    [5] => BB
)

both is not correct. 


regards 

Andreas


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


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



Thread (6 messages)

« previous php.bugs (#25090) next »