views:

768

answers:

11

How can I write not greater-than-or-equal-to in php? Is it >!=?

+81  A: 

Isn't not greater than or equal to x the same as less than x ?

Svish
@Ian P: I've added one for you ;-)
Mike
I'm not going to upvote you simply because no one should be rewarded for knowing the answer to this question.
Lucas Oman
@Lucas: haha, fair enough :p
Svish
It is incredible that an answer to this question would garner that much reputation.
BipedalShark
Well, not exactly. NaNs are supposed to be unordered.
ninjalj
@BipedalShark, I am a bit in disbelief myself O.o
Svish
I used to be against weighted reputation based on question difficulty, but this is just about the greatest example in support of it I've ever seen :)
Michael Mrozek
+3  A: 
<

(less than is the same as not greater than or equal to)

murgatroid99
+8  A: 

"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).

Neil Williams
+3  A: 

simply use < ?

Trefex
+9  A: 

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
Lizard
+1 for an imaginative answer.
Mike
Perhaps this question is a good candidate for code bowling? (The more code - higher points - is the winner)
Jeff Fohl
@Jeff Fohl: Good grief, no! We might get a distributed, parallelized, XML-backed, synergistic proactive network architecture (which somehow involves a wooden table, and whose sole purpose is to determine if x < y). There is a site for that, but it's not SO.
Piskvor
@Jeff Fohl: Does that mean that if my code is not less than or equal to your code, you will win?
Mike
New definition of mathematical induction - if something holds for 4 and 6, it is true for all integers;)
el.pescado
+1  A: 

errr,

a not greater or equal to b is equivalent to b < a

Luk
+3  A: 

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.

John Rasch
+37  A: 

Oh, fun. In increasing order of complexity:

  1. <
  2. (a - b > 0)
  3. !(a >= b)
  4. !(a - b <= 0)
  5. !((a > b) || (a==b))
  6. !(a - b < 0) && !(a - b == 0)
  7. !((a - b < 0) || (a - b == 0)) && !(!(a < b))
  8. !(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. ;)

Rab
I just have to mention that #8 will break on integer values (because of integer division) and non integer values (rounding errors messing with equality).
murgatroid99
Slow day at the office?
Ben313
hahahaha, i can't stop laughing
jordanstephens
@murgatroid Good point about #8. (+1) I must remember to avoid that issue whenever I use it. Perhaps when adding redundant operations to slow down a process, in those cases where the users are known to be evil.
Rab
@Rab isn't sleep(1) better for that?
luiscubal
+1 for sheer cheek. :-)
Platinum Azure
@luiscubal Well yeah but that would be too much like using the "<" operator ... I mean, as long as we're making things more complicated than they need to be, let's stick to it.
Rab
A: 

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 =)

Fabiano
A: 

Doing it the way you word it

!> or <>

Mowgli
+1  A: 

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
ninjalj