String comparison function; comparison function; string comparison

php strcmp() function syntax

Function:Compare two strings (case sensitive)

Syntax: strcmp(string1,string2)

Parameters:

ParametersDescription
string1 Required, specifies the first string to be compared.
string2Required, specifies the second string to be compared.

Description: strcmp() function compares two strings. The strcmp() function is binary-safe and case-sensitive. If the two strings are equal, 0 is output. If string1 is less than string2, the output value is less than 0. If string1 is greater than string2, the output value is greater than 0.

php strcmp() function example

<?php
$i = "Hello world";
$j = "HELLO WORLD";
echo strcmp($i,$j);
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

1


<?php
echo strcmp("str1", "str2");
?>

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

-1