PHP strcoll() Function

Example

Compare Strings:

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

Run Instance

Definition and Usage

The strcoll() function compares two strings.

The comparison of strings will change according to the local setting (A<a or A>a).

Note:strcoll() is case-sensitive but not binary-safe.

Note:If the current local setting is C or POSIX, the operation of this function is similar to strcmp() Same.

Syntax

strcoll(string1,string2)
Parameters Description
string1 Required. Specifies the first string to be compared.
string2 Required. Specifies the second string to be compared.

Technical Details

Return Value:

This function returns:

  • 0 - If two strings are equal
  • <0 - If string1 Less than string2
  • >0 - If string1 Greater than string2
PHP Version: 4.0.5+
Update Log: This function is applicable to win32 since PHP 4.2.3.