The strcoll Function
The strcoll function compares two strings considering the current locale. The first parameter is the first string to compare, the second is the second string. The function returns 0 if the strings are identical, a number -1 if the first string is less than the second,
and a number greater than 1 if the first string is greater than the second.
Syntax
strcoll(string1, string2);
Example
Comparing strings with different locales:
<?php
setlocale(LC_COLLATE, 'en_US.UTF-8');
$res1 = strcoll('apple', 'banana');
setlocale(LC_COLLATE, 'de_DE.UTF-8');
$res2 = strcoll('äpfel', 'zebra');
echo $res1;
echo $res2;
?>
Code execution result:
-1
-1
Example
Comparing identical strings:
<?php
setlocale(LC_COLLATE, 'ru_RU.UTF-8');
$res = strcoll('строка', 'строка');
echo $res;
?>
Code execution result:
0
See Also
-
the
strcmpfunction,
which compares strings without considering the locale -
the
strcasecmpfunction,
which compares strings case-insensitively