PHP Introduction


  1. What will be the output of the following PHP code?
    <?php
    $State = "Chennai";
    switch ($State) {
    case "Mumbai":
    echo "I love Mumbai. ";
    case "Chennai":
    echo "I love Chennai. ";
    case "Rajshathan":
    echo "I love Rajshatan. "; }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    for each loop, do-while loop, while loop and for loop of the looping statements are supported by PHP.



  1. What will be the output of the following PHP code?
    <?php
    $user = array("Ats ", "Ajit ", "Rahul ", "Aju ");
    for ($str=0; $str < count($user); $str++) {
    if ($user[$str] == "Rahul ") continue;
    printf ($user[$str]);
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.


  1. If $n = 25 what will be returned when (($n == 25) ? 5 : 1) is executed?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    ?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .



  1. What is the value of $a and $b after the function call?
    <?php
    function doSomething(&$argument)
    {
    $Result = $argument;
    $argument += 1;
    return $Result;
    }
    $n = 5;
    $m = doSomething($n);
    echo "n = " . $n . " and m = " . $m;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    $n is 6 and $m is 5. The former because $argument is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.