PHP Functions


  1. What will be the output of the following PHP code?
    <?php
    function n()
    {
    function m()
    {
    echo 'M';
    }
    echo 'N';
    }
    m();
    n();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    This will be the output- Fatal error: Call to undefined function m(). You cannot call a function which is inside a function without calling the outside function.


  1. What will be the output of the following PHP code?
    <?php
    function calculate($p, $t="")
    {
    $total = $p + ($p * $t);
    echo "$total";
    }
    calculate(65);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.



  1. What will be the output of the following PHP code?
    <?php
    function n()
    {
    function m()
    {
    echo 'M';
    }
    echo 'N';
    }
    n();
    n();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    This will be the output- I am a Fatal error: Cannot redeclare b()


  1. What will be the output of the following PHP code?
    <?php
    define("GREETING1","Welcome to interview mania!");
    define("GREETING2","Welcome to interview mania!");
    define("GREETING3","Welcome to interview mania!");
    echo defined("GREETING");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The defined() function checks whether a constant exists.



  1. What will be the output of the following PHP code?
    <?php
    $option2 = "Hey";
    function fun($option1)
    {
    echo $option1;
    echo $option2;
    }
    fun("Welcome");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    If you want to put some variables in function that was not passed by it, you must use “global”. Inside the function type global $option2.