php8.5
Home/ Manual/ strings / functions/ strcmp

strcmp

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Binary safe string comparison

Description

strcmp(string $string1, string $string2): int

Note that this comparison is case sensitive. For case-insensitive comparison, see strcasecmp().

Note that this comparison is not locale aware. For locale aware comparison see strcoll() or Collator::compare

Parameters

string1

The first string.

string2

The second string.

Return Values Return

Changelog

VersionDescription

Examples

strcmp() example

php
<?php
$var1 = "Hello";
$var2 = "hello";
if (strcmp($var1, $var2) !== 0) {
    echo '$var1 is not equal to $var2 in a case sensitive string comparison';
}
?>

See Also

Source: reference/strings/functions/strcmp.xml · from the official PHP manual (php/doc-en)