strcmp
Binary safe string comparison
strcmp()
function compares two strings.
Note: The strcmp()
function is binary-safe and case-sensitive.
Tip: This function is similar to the strncmp()
function, except that through strncmp()
you can specify the number of characters each string is used for comparison.
Compare two strings (case sensitive):
<?php echo strcmp ( "Hello world!" , "Hello world!" ) ; ?>
Try it yourself
Comparing two strings (case sensitive, Hello and hELLo outputs are different):
<?php echo strcmp ( "Hello" , "Hello" ) ; echo "<br>" ; echo strcmp ( "Hello" , "hELLo" ) ; ?>
Try it yourself
Different return values:
<?php echo strcmp ( "Hello world!" , "Hello world!" ) ; // Two strings are equal echo strcmp ( "Hello world!" , "Hello" ) ; // string1 is greater than string2 echo strcmp ( "Hello world!" , "Hello world! Hello!" ) ; // string1 is less than string2 ?>
Try it yourself
strcmp ( string1 , string2 )
parameter | describe |
---|---|
string1 | Required. Specifies the first string to be compared. |
string2 | Required. Specifies the second string to be compared. |