ExamVeda
Login
Home
21
What will be the output of the following PHP code ?
<?php
$x = 1;
if ($x = $x& 0)
    print $x ;
else
    print "how are u";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
x&0 is 0,thus evaluated to false.
22
What will be the output of the following PHP code ?
<?php
$x = 1;
if ($x = $x& 0)
    print $x;
else
    break;
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
break is not defined for a if else ladder.
23
What will be the output of the following PHP code ?
<?php
$x = 10;
$y = 5;
$z = 3;
if ($x / $y / $z)
    print "hi";
else
    print "hello";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
In php division returns a float that is a non zero value thus evaluates to true.
24
What will be the output of the following PHP code ?
<?php
if (!print "hi")
    if (print "hello")
print "hi";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Print returns true and thus the first if statement also is not executed.
25
What will be the output of the following PHP code ?
<?php
if (print "hi" - 1)
    print "hello"
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
print returns true and when 1 is subtracted it is syntax error.
26
What will be the output of the following PHP code ?
<?php
$x = 1;
if ($x--)
    print "hi"
    $x--;
else
    print "hello"
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The if statement has no brackets and it expects a else/else if after a if.
27
What will be the output of the following PHP code ?
<?php
$a = 10;
$b = 11;
if ($a < ++$a || $b < ++$b)
    print "hello";
else
    print "hi";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The operator precedence of ++ is higher than <,thus the incremenrt happens first and then compared.
28
What will be the output of the following PHP code ?
<?php
$a = 2;
if ($a-- - --$a - $a)
    print "hello";
else
    print "hi";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Computing the expression in the if clause,it sums upto to 2 which is a positive value.
29
What will be the output of the following PHP code ?
<?php
$a = 2;
if ($a-- - --$a - $a)
    print "hello";
else
    print "hi";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Computing the expression in the if clause,it sums upto to 2 which is a positive value.
30
What will be the output of the following PHP code ?
<?php
$a = "hello";
if ($a.length)
    print $a.length;
else
    print "hi";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The . operator appends a string and returns true.