PHP If Else/Else If Statement
- What will be the output of the following PHP code?
<?php
$str;
if ($str)
print "Interview" ;
else
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Uninitialized str is set to 0, thus if condition fails.
- 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.
- What will be the output of the following PHP code ?
<?php
$n;
if ($n == 0)
print "Inter" ;
else
print "Mania";
print "view"
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
else condition without brackets performs the following statements only.
- What will be the output of the following PHP code ?
<?php
$num = 12;
if (echo $num)
print "True";
else
print "False";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
echo does not return anything so if condition is empty.
- What will be the output of the following PHP code ?
<?php
$num = 15;
if (print $num)
print "Interview";
else
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
print returns 1 if it prints anything.