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 Example

Definition and Usage

The strcoll() function compares two strings.

The comparison of strings will vary according to the local settings (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 function works in the same way as strcmp() Identical.

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.