字符串的逻辑运算符有什么用
What is the use of logical operator with string
我用过if(!$url)
但我不知道PHP中下面代码的确切含义
我们可以用逻辑运算符
检查字符串吗
if (! 'redirect cart'){
// data
}
是否允许在逻辑运算中使用?
等于比较false
:
if (false == 'redirect cart') { ...
如果您的字符串为空,这可能是正确的:
if (! '') { // this condition will be met
但是用直接的字符串写这个条件是没有意义的,这应该是一个变量:
$str = my_function() ? 'redirect cart' : '';
if (!$str) { ...
!
运算符取反表达式的值。像这样的代码 $value = (!true);
将 return 为假,即 $value
将为假。当您将运算符应用于 returns false
的表达式时,也会发生同样的情况
我用过if(!$url)
但我不知道PHP中下面代码的确切含义
我们可以用逻辑运算符
if (! 'redirect cart'){
// data
}
是否允许在逻辑运算中使用?
等于比较false
:
if (false == 'redirect cart') { ...
如果您的字符串为空,这可能是正确的:
if (! '') { // this condition will be met
但是用直接的字符串写这个条件是没有意义的,这应该是一个变量:
$str = my_function() ? 'redirect cart' : '';
if (!$str) { ...
!
运算符取反表达式的值。像这样的代码 $value = (!true);
将 return 为假,即 $value
将为假。当您将运算符应用于 returns false