PHP Functions


  1. What will be the output of the following PHP code ?
    <?php
    function fun($str)
    {
    echo "hello\n".$str;
    function Z()
    {
    echo "Inside block executed...\n";
    }
    }
    function Z()
    {
    echo "Outside block executed...\n";
    }
    Z();
    fun("Interview Mania");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Function Z is declared twice.


  1. What will be the output of the following PHP code ?
    <?php
    function fun($str)
    {
    echo "Hello ".$str;
    function m()
    {
    echo "\nBlock m executed...";
    }
    }
    fun("Interview Mania");
    m();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    m is declared as fun() is executed first.



  1. What will be the output of the following PHP code ?
    <?php
    function calculation($n1, $n2)
    {
    $n3 = $n1 * $n2;
    }
    $R = calculation(12, 25);
    echo $R;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Function does not return anything.


  1. What will be the output of the following PHP code ?
    <?php
    function calculate($n1, $n2)
    {
    $n3 = $n1 * $n2;
    return $n3;
    }
    $R = calculate(22, 23);
    echo $R;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Function returns $n3.