PHP strcoll Function

What is strcoll Function?


In PHP, This function is used to compare two strings and is case-sensitive,but not binary safe.



In the above syntax "string1" specifies the first string to compare, "string2" specifies the second string to be compared, the function returns "0" if both strings are equal, returns a value ">0" if "string1" is greater than "string2", returns a value "<0" if "string1" is less than "string2".

Example :

setlocale (LC_COLLATE, 'NL');
echo strcoll("Hello World!","Hello WORLD!");
echo "<br />";
setlocale (LC_COLLATE, 'en_US');
echo strcoll("Hello WORLD!","Hello World!");
Result :


In the above strcoll Function example first string is greater than second so it returns "1", secondly it is less so it returns "-1"

PHP Topics

Ask Questions

Ask Question