strcmp() function in PHP

PHPProgrammingServer Side Programming

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

Note − This function is case-sensitive.

Syntax

strcmp(str1, str2)

Parameters

  • str1 − First string to compare

  • str2 − Second string to compare

Return

The strcmp() 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
   echo strcmp("windows","Windows");
?>

Output

The following is the output −

32

Example

Let us see another example −

 Live Demo

<?php
   echo strcmp("Windows OS","Windows Operating System");
?>

Output

The following is the output −

-7424
raja
Published on 17-Oct-2018 15:51:41
Advertisements