PHP If Else/Else 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.
- 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
$p = "0";
$q = "1";
if ((int)$p && $q)
print"Interview";
else
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The expression is evaluated with values contained in the string, even without typecasting.
- What will be the output of the following PHP code ?
<?php
if (print "Program ")
print "Executed..." ;
else
print "Not Executed...";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Expression evaluates to true as print returns 1.
- What will be the output of the following PHP code ?
<?php
$num = 5;
if ($num == 6)
print "Interveiw" ;
else if($num = 6)
print $num;
else
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Enters if else as first condition is false and thus num is set to 6.