PHP Functions


  1. What will be the output of the following PHP code ?
    <?php
    function constant()
    {
    define("MESSAGE", "Welcome to Interview Mania");
    echo MESSAGE;
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    By default constants are case sensitive. Hence an error will arise.


  1. What will be the output of the following PHP code ?
    <?php
    function fun($str)
    {
    if ($str < 50)
    return 30;
    else
    return 60;
    }
    $p = fun(100);
    if ($p < 30)
    {
    echo "Hello!";
    }
    else
    {
    echo "Hey!";
    }
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Function returns 60. this is greater than 30, hence the output.



  1. What will be the output of the following PHP code ?
    <?php
    function fun()
    {
    ECHO "Hello Interview Mania!\n";
    echo "Hello Interview Mania!\n";
    EcHo "Hello Interview Mania!\n";
    }
    fun();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Functions, keywords etc) in php are case insensitive.


  1. What will be the output of the following PHP code ?
    <?php
    function fun()
    {
    $EmailId1 = "Interview@Mania.com";
    $EmailId2 = strstr($EmailId1, '@');
    echo $EmailId2;
    }
    fun();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The strstr() function searches for the first occurrence of a string inside another string.



  1. What will be the output of the following PHP code ?
    <?php
    function str()
    {
    echo strstr("Interview Mania!", 118);
    }
    str();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    118 is the ASCII value of v.