HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

strcmp

Description

The strcmp of String for PHP binary safe string comparison.

Syntax

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

Parameters

string1

The first string.

string2

The second string.

Return

Returns a value less than 0 if string1 is less than string2; a value greater than 0 if string1 is greater than string2, and 0 if they are equal.

No particular meaning can be reliably inferred from the value aside from its sign.

Examples

1 · <

<?

$string1 = "abc";
$string2 = "xyz";

$return = strcmp($string1, $string2);

echo $return;
-23

2 · >

<?

$string1 = "xyz";
$string2 = "abc";

$return = strcmp($string1, $string2);

echo $return;
23

3 · =

<?

$string1 = "abc";
$string2 = "abc";

$return = strcmp($string1, $string2);

echo $return;
0

4 · case

<?

$string1 = "case";
$string2 = "CASE";

$return = strcmp($string1, $string2);

echo $return;
32