ExamVeda
Login
Home
1
What will be the output of the following PHP code ?
<?php
$i = 2;
while (++$i)
{   
    while ($i --> 0)
        print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The loop ends when i becomes 0.
2
What will be the output of the following PHP code ?
<?php
$i = 2;
while (++$i)
{   
    while (--$i > 0)
        print $i;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The loop never ends as i is always incremented and then decremented.
3
What will be the output of the following PHP code ?
<?php
echo 5 * 9 / 3 + 9;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Operator precedence order must be followed.
4
What will be the output of the following PHP code ?
<?php
$i = 0;
$j = 0;
if ($i &&  ($j = $i + 10)) 
{
    echo "true";
}
echo $j;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
In if condition when the first case is 0 and is an && operation then the second command is not executed.
5
What will be the output of the following PHP code ?
<?php
$i = 10;
$j = 0;
if ($i || ($j = $i + 10)) 
{
    echo "true";
}
echo $j;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
In if condition when the first case is 1 and is an || operation then the second command is not executed.
6
What will be the output of the following PHP code ?
<?php
$i = 1;
if ($i++ && ($i == 1))
    printf("Yesn$i");
else
    printf("Non$i");
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The first condition returns true and increments but the second condition is false.
7
What will be the output of the following PHP code ?
<?php
$a = 1; $b = 3;
$d = $a++ + ++$b;
echo $d;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Post increment of a is done after expression evaluation.
8
What will be the output of the following PHP code ?
<?php
$a = 1; $b = 1; $d = 1;
print ++$a + ++$a+$a++; print $a++ + ++$b; print ++$d + $d++ + $a++;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Follow the order of post and pre increments.
9
What will be the output of the following PHP code ?
<?php
$a = 10; $b = 10;
if ($a = 5)
    $b--;
print $a;print $b--;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
a is set to 5 in the if condition and b is postdecremented in the print statement.
10
What will be the output of the following PHP code ?
<?php
$i = 0;
$x = $i++; $y = ++$i;
print $x; print $y; 
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
First case i is incremented after setting x to i.