ExamVeda
Login
Home
61
What will be the output of the following PHP code ?
<?php
$x;
echo "$x";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Since the variable x is not initialised it is not storing any value, therefore nothing will be printed on the screen.
62
What will be the output of the following PHP code ?
<?php
$x = 5;
{
    $x = 10;
    echo "$x";
}
echo "$x";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Varibale x stores the value 10 and not 5.
63
What will be the output of the following PHP code ?
<?php
$x = 5;
{
    echo "$x";
}
?>
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
64
What will be the output of the following PHP code ?
<?php
$x = 5;
function fun()
{
    echo "$x";
}
fun();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The variable x is not defined inside the function fun(), therefore nothing is printed on the screen.
65
What will be the output of the following PHP code ?
<?php
$x = 5;
function fun()
{
    $x = 10;
    echo "$x";
}
fun();
echo "$x";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
First when the function is called variable x is initialised to 10 so 10 is printed later the global value 5 is printed.
66
What will be the output of the following PHP code ?
<?php
$x = 5;
function fun()
{
    $x = 10;
    echo "$x";
}
fun();
echo "$x";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
First when the function is called variable x is initialised to 10 so 10 is printed later the global value 5 is printed.
67
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);
?>
Discuss
Answer & Solution
Answer: Option D
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.
68
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);
?>
Discuss
Answer & Solution
Answer: Option A
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.
69
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); 
?>
Discuss
Answer & Solution
Answer: Option B
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.
70
What will be the output of the following PHP code ?
<?php
$x = 3, 4, 5, 6;
echo "$x";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
In C you won’t get an error but in PHP you’ll get a syntax error.