English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strcmp() Function Usage and Example

PHP String String Function Manual

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

Syntax

strcmp(string1,string2)

Definition and Usage

Used to compare two strings (case-sensitive)

Return Value

 If str1 Less than str2 Returns < 0; if str1 Greater than str2 Returns > 0; if both are equal, returns 0.

Parameter

Serial NumberParameters and Description
1

string1

It specifies the first string to be compared

2

string2

It specifies the second string to be compared

Online Example

Try the following example, compare two strings, if this function returns 0, then the two strings are equal.

<?php
   echo "If this function returns 0, then the two strings are equal.";
   echo "<br> The result is: ";
   echo strcmp("Hello world!","Hello world!");
?>
Test and see‹/›

Output Result

If this function returns 0, then the two strings are equal.
The result is: 0

PHP String String Function Manual