My Report

PHP Function Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following PHP code?

 
<?php
    function sum($num1, $num2)
    {
        $total = $num1 + $num2;
        echo "chr($total)"; 
    }
    $var1 = "sum";
    $var1(5, 44);    
?>

2. What will be the output of the following PHP code?

<?php
function one()
{
    echo " this works";
    function two()
    {
        echo "this too works";
    }
}
one();
two();
?>                   

3. What will be the output of the following PHP code?

<?php
    function b()
    {
        echo "b is executed";
    }
    function a()
    {
        b();
        echo "a is executed";
        b();
    }
    a();
  ?>

4. What will be the output of the following PHP code?

<?php
function addFunction($num1, $num2)
{
    $sum = $num1 + $num2;
    return $sum;
}
$return_value = addFunction(10, 20);
echo "Returned value from the function : $return_value"
?>

5. What will be the output of the following PHP code?

<?php
function sum($x, $y)
{
    $z = $x + $y;
    return $z;
}
echo "5 + 10 = " . sum(7,13) . "<br>";
echo "7 + 13 = " . sum(2,4) . "<br>";
echo "2 + 4 = " . sum(5,10);
?>

6. What will be the output of the following PHP code?

<?php
function addFive($num)
{
    $num += 5;
}
function addSix(&$num)
{
    $num += 6;
}
$orignum = 10;
addFive( &$orignum );
echo "Original Value is $orignum<br />";
addSix( $orignum );
echo "Original Value is $orignum<br />";
?>

7. What will be the output of the following PHP code?

<?php
    function sum($num1, $num2)
    {
        $total = $num1 + $num2;
        echo "cos($total)"; 
    }
    sum(5,-5);    
?>

8. What will be the output of the following PHP code?

<?php
function one()
{
    define("const","I am awesome!");
    echo constant("const");
}
one();
?>

9. What will be the output of the following PHP code?

<?php
function sayHello()
{
   echo "HelloWorld<br />";
}
$function_holder = "sayHello";
$function_holder();
?>

10. What will be the output of the following PHP code?

<?php
function do($myString)
{
    echo strpos($myString, "donkey",0);
}
do("The donkey looks like a horse.");
?>

 

Start practicing “1000 MCQs on PHP”, and once you are ready, you can take tests on all topics by attempting our “PHP Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.