PHP If Else/Else If Statement
- What will be the output of the following PHP code ?
<?php
if (!print "First")
if (print "Second")
print "Third";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Print returns true and thus the first if statement also is not executed.
- What will be the output of the following PHP code ?
<?php
if (print "Ninth" - 9)
print "Tenth"
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
print returns true and when 9 is subtracted it is syntax error.
- What will be the output of the following PHP code ?
<?php
$num = 1;
if ($num--)
print "First"
$num--;
else
print "Second"
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The if statement has no brackets and it expects a else/else if after a if.
- What will be the output of the following PHP code ?
<?php
$p = 25;
$q = 26;
if ($p < ++$p || $q < ++$q)
print "if statement executed...";
else
print "else statement executed...";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The operator precedence of ++ is higher than <,thus the increment happens first and then compared.
- What will be the output of the following PHP code ?
<?php
$n = 12;
if ($n-- - --$n - $n)
print "First";
else
print "Second";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Computing the expression in the if clause,it sums upto to 2 which is a positive value.