Page 1 of 1

Help plz

Posted: Fri Jun 26, 2015 1:23 pm
by hilal6
Greatings everyone AOA.

I need help with the following code

Code: Select all

<?php
$a=50;
$b=55;

if(!$a>$b)
{
	echo "b is greater than a";
}
elseif(!$b>$a){
	echo "a is greater than b";
}
else
{
	echo "a=b";	
}
?>
Why does it echo a=b and not b is greater than a?

Re: Help plz

Posted: Fri Jun 26, 2015 1:41 pm
by Celauran
Because !$a == false and false > $b == false.

Re: Help plz

Posted: Fri Jun 26, 2015 1:44 pm
by hilal6
so your saying that !$a means not $a? Meaning that it doesn't even consider the variable ? Right?

Re: Help plz

Posted: Fri Jun 26, 2015 1:48 pm
by hilal6
In this piece of code

<?php

$q="0";
if(empty($q)&&!is_numeric($q)){

echo "please enter a value";
}
?>

the reason it doesnt echo is because it converts the string to a numeric value. Right ?

Re: Help plz

Posted: Fri Jun 26, 2015 1:49 pm
by Celauran
!$a>$b == false
!($a > $b) == true