PHP - String strcoll() Function
The PHP String strcoll() function is used to compare two strings. Based on the value of two strings, the function returns the following:
- Returns a number less than 0, if first string is less than second string.
- Returns 0, if both strings are equal.
- Returns a number greater than 0, if first string is greater than second string.
Note: The strcoll() function is a case-sensitive but not a binary-safe function.
Syntax
strcoll(str1, str2)
Parameters
str1 |
Required. Specify the first string to compare |
str2 |
Required. Specify the second string to compare |
Return Value
Returns a number less than 0, if first string is less than second string.
Returns 0, if both strings are equal.
Returns a number greater than 0, if first string is greater than second string.
Example:
In the below example, strcoll() function is used to compare two strings and returns values based on the value of two strings.
<?php echo strcoll('Hello', 'Hello')."\n"; echo strcoll('World', 'Hello')."\n"; echo strcoll('Hello', 'World')."\n"; ?>
The output of the above code will be:
0 15 -15
❮ PHP String functions