note 30222 added to function.strcoll
| From: | muell-spam-trash-abfall at kcet dot de | Date: | Tue, 11 Mar 2003 13:22:25 +0000 |
| Subject: | note 30222 added to function.strcoll | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45099@lists.php.net to get a copy of this message | ||
strcoll()'s behavior is sometimes a little bit confusing. It depends on LC_COLLATE in your
locale.
<?php
$a = 'a';
$b = 'A';
print strcmp ($a, $b) . "\n"; // prints 1
setlocale (LC_COLLATE, 'C');
print "C: " . strcoll ($a, $b) . "\n"; // prints 1
setlocale (LC_COLLATE, 'de_DE');
print "de_DE: " . strcoll ($a, $b) . "\n"; // prints -2
setlocale (LC_COLLATE, 'de_CH');
print "de_CH: " . strcoll ($a, $b) . "\n"; // prints -2
setlocale (LC_COLLATE, 'en_US');
print "en_US: " . strcoll ($a, $b) . "\n"; // prints -2
?>
This is useful e. g. if want to sort an array by using strcoll:
<?php
$a = array ('a', 'A', 'ä', 'Ä', 'b',
'B');
setlocale (LC_COLLATE, 'C');
usort ($a, 'strcoll');
print_r ($a);
?>
This is like sort($a):
Array
(
[0] => A
[1] => B
[2] => a
[3] => b
[4] => Ä
[5] => ä
)
<?php
setlocale (LC_COLLATE, 'de_DE');
usort ($a, 'strcoll');
print_r ($a)
?>
This is completely different:
Array
(
[0] => a
[1] => A
[2] => ä
[3] => Ä
[4] => b
[5] => B
)
--
http://www.php.net/manual/en/function.strcoll.php
http://master.php.net/manage/user-notes.php?action=edit+30222
http://master.php.net/manage/user-notes.php?action=delete+30222
http://master.php.net/manage/user-notes.php?action=reject+30222