PHP Functions


  1. What will be the output of the following PHP code ?
    <?php
    function Condition($number)
    {
    if ($number == 3)
    echo "Condition 3rd executed....";
    if ($number == 7)
    echo "Condition 7th executed....";
    if ($number == 8)
    echo "Condition 8th executed....";
    if ($number == 19)
    echo "Condition 19th executed....";
    }
    $var = stripos("I know the php, And I love to know php!","the");
    Condition($var);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The stripos() function finds the position of the first occurrence of a string inside another string. In this case it returns 7.


  1. What will be the output of the following PHP code ?
    <?php
    function fun($m)
    {
    if ($m < 10)
    echo "True";
    if ($m >= 10)
    echo "False";
    }
    fun(20);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Argument is 20.



  1. What will be the output of the following PHP code ?
    <?php 
    $p = 45;
    $q = 26;
    function add()
    {
    $GLOBALS['r'] = $GLOBALS['p'] + $GLOBALS['q'];
    }
    add();
    echo $r;
    ?>












  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    r is a variable present within the $GLOBALS array, it is also accessible from outside the function!


  1. What will be the output of the following PHP code ?
    <?php
    function 15function()
    {
    echo "Hello Interview Mania";
    }
    15function();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Function cannot begin with a number.



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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Function Beginning with “_” is valid)