PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hilal6
Forum Newbie
Posts: 6 Joined: Fri Jun 26, 2015 1:15 pm
Post
by hilal6 » Fri Jun 26, 2015 1:23 pm
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?
Last edited by
hilal6 on Fri Jun 26, 2015 1:45 pm, edited 1 time in total.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jun 26, 2015 1:41 pm
Because !$a == false and false > $b == false.
hilal6
Forum Newbie
Posts: 6 Joined: Fri Jun 26, 2015 1:15 pm
Post
by hilal6 » Fri Jun 26, 2015 1:44 pm
so your saying that !$a means not $a? Meaning that it doesn't even consider the variable ? Right?
hilal6
Forum Newbie
Posts: 6 Joined: Fri Jun 26, 2015 1:15 pm
Post
by hilal6 » Fri Jun 26, 2015 1:48 pm
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 ?
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jun 26, 2015 1:49 pm
!$a>$b == false
!($a > $b) == true