ExamVeda
Login
Home
81
What will be the output of the following PHP code ?
<?php
$x = 0;
function fun()
{
    echo $GLOBALS['x'];
    $x++;
}
fun();
fun();
fun();
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
This question is similar to question 6.
82
What will be the output of the following PHP code ?
<?php
$a = 10;
echo ++$a;
echo $a++;
echo $a;
echo ++$a;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
++$a increments a and then prints it,$a++ prints and then increments.
83
What will be the output of the following PHP code ?
<?php
$a = 12;
--$a;
echo $a++;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The + operator does union of arrays in that order, then the === operator compares key and value pairs.
84
What will be the output of the following PHP code ?
<?php
$x = "test";
$y = "this";
$z = "also"; 
$x .= $y .= $z ;
echo $x;
echo $y;
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The x .= y is a shorthand for x = x.y and this is evaluated from right to left.
85
What will be the output of the following PHP code ?
<?php
$x = 1;
$y = 2;
if (++$x == $y++)
{
    echo "true ", $y, $x;
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
x is preincremented and y is post incremented thus both are 2 in the if condition, later y is incremented.
86
What will be the output of the following PHP code ?
<?php
$y = 2;
$w = 4;
$y *= $w /= $y;
echo $y, $w;
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
Expression is evaluated from right to left.
87
What will be the output of the following PHP code ?
<?php
$y = 2;
if ($y-- == ++$y)
{
    echo $y;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
First $y = 2 is compared to and then decremented, then incremented and compared to $y = 2.
88
What will be the output of the following PHP code ?
<?php
$y = 2;
if (**$y == 4)
{
    echo $y;
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The ** is not a valid operator,only ++ and — exist.
89
What will be the output of the following PHP code ?
<?php
$y = 2;
if (--$y == 2 || $y xor --$y)
{
    echo $y;
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
–$y == 2 is false but y is decremented, the xor gives true if only one of the operands are true, thus 1 xor 0 is true.
90
What will be the output of the following PHP code ?
<?php
$y = 2;
if (--$y <> ($y != $y++))
{
    echo $y;
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
–$y == 2 is false but y is decremented, the xor gives true if only one of the operands are true, thus 1 xor 0 is true.