This article introduces one or two kinds of character comparison methods in PHP, one is = = number, one is the strcmp function for string equality comparison, the need for friends can refer to.
Compare using the function strcmp () function string
int strcmp (string str1,string str2))
The parameter str1 and the parameter str2 the two strings to compare, or 0 if they are equal, if the parameter str1 is greater than the parameter str2 the return value is greater than 0, and the return value is less than 0 if the parameter str1 is less than the parameter str2.
Instance:
| The code is as follows |
Copy Code |
$str 1= "a"; Defining string Constants $str 2= "B"; Defining string Constants $str 3= "CCC"; Defining string Constants $str 4= "CCC"; Defining string Constants Echo strcmp ($str 1, $str 2);//The two strings are equal Echo strcmp ($str 3, $str 4);//Note that this function is case-sensitive ?>
|
Note: This function distinguishes the case of letters.
Use = = to compare
| The code is as follows |
Copy Code |
$a = "Joe"; $b = "Jerry"; if ($a! = $b) { echo "Unequal"; } Else { echo "equal"; } |
For more detailed information, please see: http://www.bKjia.c0m/phper/php-function/35413.htm
http://www.bkjia.com/PHPjc/629266.html www.bkjia.com true http://www.bkjia.com/PHPjc/629266.html techarticle This article introduces one or two kinds of character comparison methods in PHP, one is = = number, one is the strcmp function for string equality comparison, the need for friends can refer to. Using the function strcmp () function ...