ExamVeda
Login
Home
91
What will be the output of the following PHP code ?

<?php
echo $x-- != ++$x;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Automatically x is declared and initialized to 0,then decremented and compared with its increments, thus returns 1.
92
What will be the output of the following PHP code ?
<?php
$auth = 1;
$status = 1;
if ($result = (($auth == 1) && ($status != 0)))
{
    print "result is $result";
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Result is x&&y which returns 1 if both x and y are true.
93
What will be the output of the following PHP code ?
<?php
$i = 0;
while ($i = 10)
{   
    print "hi";
}
print "hello";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
While condition always gives 1.
94
What will be the output of the following PHP code ?
<?php
$i = "";
while ($i = 10)
{   
    print "hi";
}
print "hello";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
While condition always gives 1.
95
What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0)
{   
    $i++;
    print $i;
    print "hello";
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
i is decremented in the first while execution and then continuously incremented back.
96
What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0 && ++$i)
{   
    print $i;
}<
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
As it is && operator it is being incremented and decremented continuously.
97
What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0 || ++$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
As it is || operator the second expression is not evaluated till i becomes 1 then it goes into a loop.
98
What will be the output of the following PHP code ?
<?php
$i = 0;
while(++$i || --$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
As it is || operator the second expression is not evaluated and i is always incremented, in the first case to 1.
99
What will be the output of the following PHP code ?
<?php
$i = 0;
while (++$i && --$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The first conditio itsef fails thus the loop exits.
100
What will be the output of the following PHP code ?
<?php
$i = 0;
while ((--$i > ++$i) - 1)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
(–$i > ++$i) evaluates to 0 but -1 makes it enters the loop and prints i which is 0.