strcoll() function in PHP


The strcoll() function is used to compare two strings based on locale.

Note − This function is case-sensitive

Syntax

strcoll(str1, str2)

Parameters

  • str1 − First string to compare

  • str2 − Second string to compare

Return

The strcoll() function returns −

  • 0 − if the two strings are equal

  • < 0 − if string1 is less than string2

  • > 0 − if string1 is greater than string2

Example

The following is an example −

Live Demo

<?php
   setlocale (LC_COLLATE, 'en_US'); 
   echo strcoll("Demo text!","Demo text!");
?>

Output

0

Example

The following is an example −

Live Demo

<?php
   $x = 'a'; $y = 'A';
   setlocale (LC_COLLATE, 'de_CH'); 
   print "de_CH: " . strcoll ($x, $y) . "
"; ?>

Output

de_CH: 32

Updated on: 30-Jul-2019

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements