PHP Operators
- What will be the output of the following PHP code ?
<?php
$k = -1;
while (++$k && --$k)
{
print $k;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The first condition itself fails thus the loop exits.
- What will be the output of the following PHP code ?
<?php
$p = 2;
while ((--$p > ++$p) - 2)
{
print $p;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
(–$p > ++$p) evaluates to 2 but -2 makes it enters the loop and prints p which is 2.
- What will be the output of the following PHP code ?
<?php
echo 10 * 15 / 12 + 14
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Operator precedence order must be followed.
- What will be the output of the following PHP code ?
<?php
$p = 20;
$q = 10;
if ($p || ($q = $p + 10)) {
echo "True";
}
echo $q;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In if condition when the first case is 1 and is an || operation then the second command is not executed.
- What will be the output of the following PHP code ?
<?php
$n = 10;
$m = 10;
if ($n && ($m = $n + 10)) {
echo "True";
}
echo $m;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In if condition when the first case is 10 and is an && operation then the second command is executed.