PHP string strcoll() Functionstrcoll() is an inbuilt string function of PHP, which is used to compare two strings. It is a locale based string comparison. It is important to notice that the comparison done by strcoll() function is case-sensitive as strcmp(), which means it treats capital and small case differently during the comparison. But, it is not binary safe like strcmp() function. Note: strcoll() function is case sensitive and it is not binary safe unlike strcmp() function.Syntax:ParametersThis function takes two strings which are mandatory to pass into the parameter. Description of the following parameters is given below.
Both parameters are mandatory to pass into the function. Value returns by strcoll()Strcoll() returns a random integer value which depends on matching condition. Return 0 - It returns 0 if both strings are equal, i.e., $str1 = $str2 Return < 0 - It returns negative value (<0), if first string is lesser than second string, i.e., $str1 < $str2 Return > 0 - It will return positive value (>0), if first string is greater than second string, i.e., $str1 > $str2 Note: It calculates ASCII value of the string and then compares both strings to check whether they are equal, greater or less from each other.Example 1Output: 0 because both strings are equal. 1 because the first string is greater than the second string. Example 2Output: -1 because the first string is less than the second string. 1 because the first string is greater than the second string. Example 3Output: 1 because the first string is greater than the second string. -1 because the first string is less than the second string. There is a table given below which contains some easy and simple example with their explanation of strcoll() function to understand it more quickly.
Next TopicPHP String |