Computer >> Computer tutorials >  >> Programming >> PHP

strcasecmp() function in PHP


The strcasecmp() function is used to compare two strings.

Note − The strcasecmp() function is case-insensitive

Syntax

strcasecmp(str1, str2)

Parameters

  • str1 − First string

  • str2 − Second string

Return

The strcasecmp() 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 −

<?php
   echo strcasecmp("Amit","AMIT");
?>

Output

The following is the output −

0

Example

Let us see another example −

<?php
   $val1 = "Tom";
   $val2 = "tom";
   if (strcasecmp($val1, $val2) == 0) {
      echo '$va11 is equal to $val2';
   }
?>

Output

The following is the output −

$va11 is equal to $val2