In PHP, you can use the strcmp() function to determine whether the strings are the same. The syntax format is "strcmp(String 1, String 2)"; if the return value is 0, the strings are the same. If the return value is greater than 0, string 1 is greater than string 2. If the return value is less than 0, string 1 is less than string 2.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP determines whether two strings are consistent Not the same
In PHP, to determine whether two strings are consistent, it is recommended to use the strcmp() method:
$result="fail"; if (strcmp($result,"success" )==0) { //相同 echo("
success"); }else{ //不相同 echo("
fail"); }
Description:
strcmp() function comparison Two strings.
Syntax
strcmp(string1,string2)
Parameters | Description |
---|---|
string1 | Required. Specifies the first string to compare. |
string2 | Required. Specifies the second string to be compared. |
Return value: | The function returns:
|
---|
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether strings are the same in php. For more information, please follow other related articles on the PHP Chinese website!