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

strncmp

Description

The strncmp of String for PHP binary safe string comparison of the first n characters.

Syntax

strncmp(
    string $string1,
    string $string2,
    int $length
): int

Parameters

string1

The first string.

string2

The second string.

length

The number of characters to use in the comparison.

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";
$length = 3;

$return = strncmp($string1, $string2, $length);

echo $return;
-23

2 · >

<?

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

$return = strncmp($string1, $string2, $length);

echo $return;
23

3 · =

<?

$string1 = "abc";
$string2 = "abc";
$length = 3;

$return = strncmp($string1, $string2, $length);

echo $return;
0

4 · case

<?

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

$return = strncmp($string1, $string2, $length);

echo $return;
32