PHP strcoll Function

What is strcoll Function?

Explanation

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

Syntax:


strcoll(string1,string2)

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 :


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

1
-1

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