Examveda
Examveda

What will be the output of the following PHP code ?
<?php
$x = 5;
function fun()
{
    $x = 10;
    echo "$x";
}
fun();
echo "$x";
?>

A. 0

B. 105

C. 510

D. Error

Answer: Option B

Solution(By Examveda Team)

First when the function is called variable x is initialised to 10 so 10 is printed later the global value 5 is printed.

This Question Belongs to PHP >> Operators And Expressions In Php

Join The Discussion

Related Questions on Operators and Expressions in php