PHP ZCE mock test, interview preparation, daily lessons under chalk talk

Friday, March 30, 2012

Output of the below code?

What will be output of the below code?

<?php
$a=array(1,2,3);
$b=array(4,5,6);
$c=1;
$a[$c++]=$b[$c++];
print_r($a);
?>

a) Array(1,4,3)
b) Array(1,6,3)
c) Array(4,2,6)
d) Array(1,5,3)
e) Array(1,2,5)



Solution: b) Array(1,6,3)
Now take some time and think how we got this solution!

At first we assume that right side of = is calculated first and is then assigned to left side.
So $b[$c++] should return 5, by then $c would have reached to 2 so $a[2]=5;
and output should be Array(1,2,5)

But what actually happens is that left side of = is calculated first, and then the right B-)

Thursday, March 15, 2012

Output of the below code?

What will be the output of the below code?


<?php
$a=0;
echo empty($a),isset($a);
?>

a) 10
b) 11
c) Syntax Error
d) 0


Solution: b) 11
Please tell me how?