My Report

PHP Programming Practice Test 1


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
$a = array("a" => "india", "b" => "brazil", "c" => "china");
echo array_shift($a);
echo "<br>";
array_pop($a);
print_r($a);
?> 

2. Which one of the following functions can be used to compress a string?

3. Which function returns an array consisting of associative key/value pairs?

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

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

5. Which of the following PHP statement/statements will store 111 in variable num?

    i) int $num = 111;
    ii) int mum = 111;
    iii) $num = 111;
    iv) 111 = $num;

6. Which type of function call is used in line 8 in the following PHP code?

    <?php
    function calc($price, $tax)	
    {
        $total = $price + $tax;
    }
    $pricetag = 15;
    $taxtag = 3;
    calc($pricetag, $taxtag);	
    ?> 
       

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

    <?php
    $team = "arsenal";
    switch ($team) {
    case "manu":
        echo "I love man u";
    case "arsenal":
        echo "I love arsenal";
    case "manc":
        echo "I love manc"; }
    ?>
    

8. Which of the looping statements is/are supported by PHP?

i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop

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

    <?php
    $total = "25 students";
    $more = 10;
    $total = $total + $more;
    echo "$total";
    ?>
    

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

<?php
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
$a2 = array("e" => "red", "f" => "green", "g" => "blue", "h" => "orange");
$a3 = array("i" => "orange");
$a4 = array_merge($a2, $a3);
$result = array_diff($a1, $a4);
print_r($result);
?>

 

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.