如何在 PHP 中编写不大于或等于?
是>!=吗?
不not greater than or equal to x一样less than x吗?
有趣哦。按照复杂度递增的顺序:
就个人而言,我会为真正惹恼我的人保留#8。;)
The best way to write this is
$x = 4;
$y = 6;
if($x < $y) echo "True";
// True
$x = 4;
$y = 6;
if(!($x >= $y)) echo "True";
// True
“不大于或等于”相当于您写为 的“严格小于” <。
如果你真的想说“不大于或等于”,你可以写!(a >= b).
<
(小于等于不大于等于)
从技术上讲,您问了两个不同的问题 - 如何编写A not greater than B or A equal to B和A not equal to B or A greater than B.
该声明A not greater than B or A equal to B暗示:
!(A > B) || A == B
这是一个重言式:
A <= B
并A not equal to B or A greater than B暗示:
A != B || A > B
这是一个重言式:
A >= B
的其他答案A < B代表该陈述A not greater than nor A equal to B。
简单地使用<?
为了证明不信者小于等于不大于等于:
<?
$i = acos(4);
print $i."\n";
print is_nan($i)."\n";
if (4>=$i) {
print "ge\n";
} else {
print "nge\n";
}
if (4<$i) {
print "lt\n";
} else {
print "nlt\n";
}
?>
它在我的系统上输出:
$ php5 nan.php
NAN
1
ge
lt
a不大于或等于b等于b < a
看看这个页面:http ://www.php.net/manual/en/language.operators.logical.php
它展示了有关运算符的有趣内容以及如何使用它们...我已经突出显示了这个特定的逻辑运算符页面,因为当您使用它们的相似之处时,它们尤其具有不同的行为,例如“||” 和“或”。
值得一看 =)
照你说的做
!> 或 <>
一些简单的例子:
<?php
#not lower than 5 AND not greater than 12
if(!($nr<5)&&!($nr>12)){ }
?>
假设您要测试 A 不等于或大于 B;
假如说 :
A = 10;
B = 20;
对于正常比较,代码看起来像这样:
if(A >= B)
{
return "A and B are equal";
}
else {
return "A and B are not equal";
}
如果上面的代码是用给定的值执行的,那么我们会认为A and B are not equal10 的语句不大于或等于 20。
现在来测试反向,或者the negated version of A >= B我们只需通过NOT symbol (!)在表达式中添加来反转它来实现它。
if(!(A >= B))
{
return "A and B are not equal";
}
else {
return "A and be are equal";
}
运行上述代码的预期响应是该语句A and B are not equal将被返回。