PHP strcoll() Function (original) (raw)

Last Updated : 11 Jul, 2025

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.

  1. $string1: This parameter refers to the first string to be used in the comparison.
  2. $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:

Examples:

Input : string1="geeksforgeeks"string1 = "geeks for geeks" string1="geeksforgeeks"string2="geeks for geeks" Output : 0

Input : string1="striver"string1 = "striver" string1="striver"string2="raj" Output : 1

Below programs illustrate the use of strcoll() function:Program 1: The below program demonstrates the return value when two equal strings are passed

PHP `

`

Output:

0

Program 2: The below program demonstrates the return value when string1 is greater than string2

PHP `

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 `

string1) $string1 = "CPP"; $string2 = "PHP"; // prints <0 echo strcoll($string1, $string2); ?>

`

Output:

-13

Reference:https://www.php.net/manual/en/function.strcoll.php