PHP Operators
- What will be the output of the following PHP code ?
<?php
$num = 8;
while (--$num > 0 || ++$num)
{
print $num;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
As it is || operator the second expression is not evaluated till num becomes 1 then it goes into a loop.
- What will be the output of the following PHP code ?
<?php
$n = 15;
while (--$n > 0 && ++$n)
{
print $n;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
As it is && operator it is being incremented and decremented continuously.
- What will be the output of the following PHP code ?
<?php
$k = 10;
while (--$k > 0)
{
$k++;
print $k;
print "Interview Mania";
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
k is decremented in the first while execution and then continuously incremented back.
- What will be the output of the following PHP code ?
<?php
$s = 4;
$t = 8;
$s *= $t /= $s;
echo $s, $t;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Expression is evaluated from right to left.
- What will be the output of the following PHP code ?
<?php
$p = 5;
$q = 6;
if (++$p == $q++)
{
echo "true ", $q, $p;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
p is preincremented and q is post incremented thus both are 6 in the if condition, later q is increment.