PHP If Else/Else If Statement
- What will be the output of the following PHP code ?
<?php
$n1 = 17;
$n2 = 19;
if ($n1 > $n2 + $n2 != 3)
print "Interview" ;
else
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Expression evaluates to true.
- What will be the output of the following PHP code ?
<?php
$str = "s";
if ($str)
print "Executed....";
else
print "Not Executed...";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The value of str is evaluated to 1 as it has a value.
- What will be the output of the following PHP code ?
<?php
$num = "";
if ($num)
print "Second";
else
print "First";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Empty string is evaluated to 0.
- What will be the output of the following PHP code ?
<?php
$num = 5;
if (5)
print "First";
if
else
print "Second";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
No else statement to end the if statement.
- What will be the output of the following PHP code ?
<?php
$n = 5;
if ($n++)
print "Hello Interview Mania";
else
print "Hey Interview Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
n is incremented after if which evaluates to false.