This article introduces one or two character comparison methods in PHP. One is the == sign, and the other is the strcmp function for string equality comparison. Friends in need can refer to it.
Use the function strcmp() function string to compare
int strcmp(string str1,string str2))
Parameters str1 and parameter str2 specify the two strings to be compared. If they are equal, 0 is returned; if parameter str1 is greater than parameter str2, the return value is greater than 0; if parameter str1 is less than parameter str2, the return value is less than 0.
Example:
The code is as follows
代码如下 |
复制代码 |
$str1=”a”; //定义字符串常量
$str2=”b”; //定义字符串常量
$str3=”ccc”; //定义字符串常量
$str4=”CCC”; //定义字符串常量
echo strcmp($str1,$str2);//这两个字符串相等
echo strcmp($str3,$str4);//注意该函数区分大小写
?>
|
|
Copy code
|
$str1="a"; //Define string constant
$str2="b"; //Define string constant
代码如下 |
复制代码 |
$a = "joe";
$b = "jerry";
if ($a != $b)
{
echo "不相等";
}
else
{
echo "相等";
}
|
$str3="ccc"; //Define string constants
$str4="CCC"; //Define string constants
echo strcmp($str1,$str2);//These two strings are equal |
echo strcmp($str3,$str4);//Note that this function is case-sensitive
?>
Note: This function is case-sensitive.
Compare using ==
The code is as follows
|
Copy code
$a = "joe";
$b = "jerry";
if ($a != $b)
{
echo "not equal";
}
else
{
}
For more details, please see: http://www.bKjia.c0m/phper/php-function/35413.htm
http://www.bkjia.com/PHPjc/629266.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629266.htmlTechArticleThis article introduces one or two character comparison methods in php, one is the == sign, and the other is strcmp The function performs string equality comparison, friends in need can refer to it. Using the function strcmp() function...
|
|
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn