PHP | strcoll() Function
The strcoll() is an inbuilt function in PHP and is used to compare two strings. This function is case-sensitive which points that capital and small cases will be treated differently, during a comparison. This function compares two strings and tells us that whether the first string is greater or smaller than the second string or equals to the second string.
Syntax:
strcoll($string1, $string2)
Parameters:The function accepts two mandatory string parameters which are described below.
- $string1: This parameter refers to the first string to be used in the comparison.
- $string2: This parameter refers to the second string to be used in the comparison.
Return Value: The function returns a random integer value depending on the condition of match, which is given by:
- Returns 0 if the strings are equal.
- Returns a negative value (<0), if $string1 is lesser than $string2.
- Returns a positive value (>0) if $string2 is lesser than $string1.
Examples:
Input : $string1 = "geeks for geeks" $string2="geeks for geeks" Output : 0 Input : $string1 = "striver" $string2="raj" Output : 1
Below programs illustrate the use of strcoll() fucntion:
Program 1: The below program demonstrates the return value when two equal strings are passed
<?php //PHP program to compare two strings using // strcoll() function (two strings are equal) $string1 = "geeks for geeks"; $string2 = "geeks for geeks"; // prints 0 as two strings are equal echo strcoll($string1, $string2); ?> |
Output:
0
Program 2: The below program demonstrates the return value when string1 is greater than string2
<?php //PHP program to compare two strings using // strcoll() function (string1>string2) $string1 = "striver"; $string2 = "raj"; // prints > 0 echo strcoll($string1, $string2); ?> |
Output:
1
Program 3: The below program demonstrates the return value when string2 is greater than string1
<?php //PHP program to compare two strings using // strcoll() function (string2>string1) $string1 = "CPP"; $string2 = "PHP"; // prints <0 echo strcoll($string1, $string2); ?> |
Output:
-13
Reference:
http://php.net/manual/en/function.strcoll.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | key() Function
- PHP | pos() Function
- p5.js | value() Function
- p5.js | hue() function
- D3.js | d3.hsl() Function
- PHP | sin( ) Function
- p5.js | min() function
- PHP | Ds\Set last() Function
- PHP | Ds\Set first() Function
- CSS | url() Function
- PHP | end() Function
- p5.js | second() function
- PHP | Ds\Map get() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



