PHP Functions


  1. What will be the output of the following PHP code?
    <?php
    function calc1(&$n)
    {
    $n += 7;
    }
    function calc2(&$n)
    {
    $n += 8;
    }
    $OrignalNumber = 12;
    calc1( $OrignalNumber );
    echo "Original Number is $OrignalNumber\n";
    calc2( $OrignalNumber );
    echo "Original Number is $OrignalNumber\n";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    calc2() passes value of the variable by reference.


  1. What will be the output of the following PHP code?
    <?php
    function addation($n1, $n2)
    {
    $add = $n1 + $n2;
    return $add;
    }
    $return_val = addation(50, 70);
    echo "Returned value : $return_val"
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Functions returns value 120.



  1. What will be the output of the following PHP code?
    <?php
    function HelloFuncation()
    {
    echo "Hello Interview Mania\n";
    }
    $fun_holder = "HelloFuncation";
    $fun_holder();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    It is possible to assign function names as strings to variables and then treat these variables exactly as you would the function name itself.


  1. What will be the output of the following PHP code?
    <?php
    function First()
    {
    echo "Function First executed...\n";
    function Second()
    {
    echo "Function Second executed...";
    }
    }
    First();
    Second();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Second is declared in First and is called after First.Hence it works.



  1. What will be the output of the following PHP code?
    <?php
    function fun($Str)
    {
    echo strpos($Str, "good",0);
    }
    fun("The Interview Mania is good for study.");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    good starts from position 23 in string.