How can I write not greater-than-or-equal-to in php? Is it >!=?
"not greater than or equal to" is equivalent to "strictly less than" which you write as <
.
If you really wanted to say "not greater than or equal to" you could just write !(a >= b)
.
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
Technically, you have asked two different questions - how to write A not greater than B or A equal to B
and A not equal to B or A greater than B
.
The statement A not greater than B or A equal to B
implies:
!(A > B) || A == B
which is a tautology for:
A <= B
And A not equal to B or A greater than B
implies:
A != B || A > B
which is a tautology for:
A >= B
The other answers of A < B
are representative of the statement A not greater than nor A equal to B
.
Oh, fun. In increasing order of complexity:
- <
- (a - b > 0)
- !(a >= b)
- !(a - b <= 0)
- !((a > b) || (a==b))
- !(a - b < 0) && !(a - b == 0)
- !((a - b < 0) || (a - b == 0)) && !(!(a < b))
- !(a - b < ((a * (1/a)-1) * (b * (1/b)-1))) && !(a - b == (a * (1/a)-1) * (b * (1/b)-1)))
Personally, I would reserve #8 for someone who really annoyed me. ;)
Take a look at this page: http://www.php.net/manual/en/language.operators.logical.php
It shows interesting things about operators and how to use them... I've highlighted this specific logical operators page because these, in particular, has different behaviors when you use their similars, like "||" and "or".
It's worth to take a look =)
To prove the disbelievers that less than is different than not greater or equal:
<?
$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";
}
?>
It outputs this on my system:
$ php5 nan.php
NAN
1
ge
lt