ExamVeda
Login
Home
51
What will be the output of the following PHP code ?
<?php
function TV($string)
{
  echo "my favourite TV show is ".$string;
  function b()
  {
      echo " I am here to spoil this code";
  }
}
function b()
{
  echo " I am here to spoil this code";
}
b();
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
This one works because b is declared independent of TV() also.
52
What will be the output of the following PHP code ?
<?php
function TV($string)
{
  echo "my favourite TV show is ".$string;
  function b()
  {
      echo " I am here to spoil this code";
  }
}
function b()
{
  echo " I am here to spoil this code";
}
b();
TV("Sherlock");
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Function b is declared twice.
53
What will be the output of the following PHP code ?
<?php
function TV($string)
{
  echo "my favourite TV show is ".$string;
  function b()
  {
    echo " I am here to spoil this code";
  }
}
a("Sherlock");
b();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
b is declared as TV() is executed first.
54
What will be the output of the following PHP code ?
<?php
function calc($num1, $num2)
{
    $total = $num1 * $num2; 
}
$result = calc(42, 0);
echo $result;    
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Function does not return anything.
55
What will be the output of the following PHP code ?
<?php
function calc($num1, $num2)
{
    $total = $num1 * $num2;
    return $total; 
}
$result = calc(42, 0);
echo $result;    
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Function returns $total.
56
What will be the output of the following PHP code ?
<?php
$var = 10;
function one()
{
    echo $var;
}
one();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
$var is not global and hence is not available for one().
57
What will be the output of the following PHP code ?
<?php
function mine($m)
{
    if ($m < 0)
        echo "less than 0";
    if ($ >= 0)
        echo "Not True";
}
mine(0);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Argument is 0.
58
What will be the output of the following PHP code ?
<?php 
$x = 75;
$y = 25; 
function addition()
{
    $GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}
addition();
echo $z;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
z is a variable present within the $GLOBALS array, it is also accessible from outside the function!
59
What will be the output of the following PHP code ?
<?php
function 2myfunc()
{
    echo "Hello World";
}
2myfunc();
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Function cannot begin with a number.
60
What will be the output of the following PHP code ?
<?php
function _func()
{
    echo "Hello World";
}
_func();
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Function Begining with “_” is valid)