Home >>PHP String Functions >PHP strcmp() Function
PHP strcmp() function is used to compare two given strings. It compares the two given strings and tells us whether the first string is greater or smaller than the second string or equals to the second string. It is case-sensitive and binary safe.
Syntax:
strcmp($string1, $string2);
Parameter | Description |
---|---|
string1 | This is a required parameter. This parameter defines the first string to compare. |
string2 | This is a required parameter. This parameter defines the second string to compare. |
Here is an example of strcmp() function in PHP:
<html> <body> <?php echo strcmp("PHPTPOINT","PHPTPOINT"); // it returns zero when both strings are same ?> </body> </html>
Here is an another example of strcmp() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo strcmp($str,"PHPTPOINT")."<br>"; // both the strings are equal echo strcmp($str,"PHP")."<br>"; // first string is greater than second string echo strcmp($str,"PHPTPOINT Noida")."<br>"; // first string is less than second string ?> </body> </html>