Operators And Expressions In Php - Study Mode

[#111] What will be the output of the following PHP code ? <?php $x = 4
$y = 3
function fun ( $x = 3 , $y = 4 ) { $z = $x + $y / $y + $x
echo "$z"
} echo $x
echo $y
echo $z
fun ( $x, $y )
?>
Correct Answer

(D) 439

Explanation

Solution: Firstly, the statements outside the function are printed, since z is not defined it’ll no value is printed for z. Next the function is called and the value of z inside the function is printed.

[#112] What will be the output of the following PHP code ? <?php $x = 4
$y = 3
function fun ( $x, $y ) { $z = $x + $y / $y + $x
echo "$z"
} echo $x
echo $y
echo $z
fun ( 3 , 4 )
?>
Correct Answer

(A) 437

Explanation

Solution: It is same as above but the value passed into the function is 3,4 and not 4,3. Therefore the difference in answer.

[#113] What will be the output of the following PHP code ? <?php function fun ( $x,$y ) { $x = 4
$y = 3
$z = $x + $y / $y + $x
echo "$z"
} fun ( 3 , 4 )
?>
Correct Answer

(B) 9

Explanation

Solution: Value 3, 4 is passed to the function but that is lost because x and y are initialised to 4 and 3 inside the function. Therefore we get the given result.

[#114] What will be the output of the following PHP code ? <?php $x = 3 , 4 , 5 , 6
echo "$x"
?>
Correct Answer

(D) Error

Explanation

Solution: In C you won’t get an error but in PHP you’ll get a syntax error.

[#115] What will be the output of the following PHP code ? <?php $a = '12345'
print "qwe" . $a . "rty"
?>
Correct Answer

(A) qwe12345rty

Explanation

Solution: dereferences the variable/string within.