My Report

PHP Programming Practice Test 10


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 b()
    {
        echo "b is executed";
    }
    function a()
    {
        b();
        echo "a is executed";
        b();
    }
    a();
  ?>

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

    <?php
    $op2 = "blabla";
    function foo($op1)
    {
        echo $op1;
        echo $op2;
    }
    foo("hello");
    ?>

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

<?php
    function string($title);
    {
        $title = ucwords($title);
        echo lcfirst($title);
    }
    string("you went full retard");
?>

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

<?php
    function calc($num1, $num2)
    {
        $total = $num1 * $num2; 
    }
    $result = calc(42, 0);
    echo $result;    
?>

5. 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;    
?>

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

<?php
    function uppercase($string)
    {
        echo ucwords($string);
    }
    $wow = "uppercase";
    $wow("Time to live king size");
?> 

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

<?php
for(;;)
{
   print "10";
}
?>

8. 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 />";
?>

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

    <?php
        function foo($msg)
        {
            echo "$msg";
        }
        $var1 = "foo";
        $var1("will this work");
    ?>

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

<?php
for ($i = 0; $i % ++$i; $i++) 
{
    print"i";
}
?>

 

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.