ExamVeda
Login
Home
41
What will be the output of the following PHP code ?
<?php
class myObject { }
define('myObject::CONSTANT', 'test');
echo myObject::CONSTANT; 
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Class constants cannot be defined outside class.
42
What will be the output of the following PHP code ?
<?php
$x = 5;
$y = 10;
$z = "$x + $y";
echo "$z";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Variable z will store 10 + 5 because 10 + 5 is given in double-quotes.
43
What will be the output of the following PHP code ?
<?php
$x = 4;
$y = 3;
$z = 1;
echo "$x = $x + $y + $z";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Again since the variables are inside double quotes we get this result.
44
What will be the output of the following PHP code ?
<?php
$x = 4;
$y = 3
$z = 1;
$z = $z + $x + $y;
echo "$z";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Normal addition of variables x, y and z occurs and result of 8 will be displayed.
45
What will be the output of the following PHP code ?
<?php
$x = 3.3;
$y = 2;
echo $x % $y;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
% is the modulo operator. Unlike in C we can use it get reminder or floating point numbers in PHP.
46
What will be the output of the following PHP code ?
<?php
$x = 10;
$y = 4;
$z = 3;
echo $x % $y % $z;
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The expression is considered as ($x%$y)%z in this case (10%4)%3 which is 2.
47
What will be the output of the following PHP code ?
<?php
$x = 10;
$y = 4;
$z = 3;
echo ($x % ($y) + $z);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The inner most bracket is evaluated first, since it covers only variable y it is as good as not using brackets.
48
What will be the output of the following PHP code ?
<?php
$x = 30;
$y = 20;
$z = 10;
echo $x + $y - $z / ($z - $y);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
First ($z – $y) is evalulated then -$z/($z – $y) is evaluated this results in 1 which is added to $x + $y therefore we get 51.
49
What will be the output of the following PHP code ?
<?php
$x = 4;
$y = -3;
$z = 11;
echo 4 + $y * $z / $x;
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
First the * is evaluated then / followed by + therefore we can rewrite this expression as 4 +((- 3 * 11) / 4) which results in -4.25.
50
What will be the output of the following PHP code ?
<?php
$x = 3.5;
$y = 2;
$z = 2;
echo $x / $y / $z;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
First $x / $y is evaluated then this is divided by $z therefore we get 0.875.