PHP Functions


  1. What will be the output of the following PHP code ?
    <?php
    $num = 120;
    function calc()
    {
    echo $num;
    }
    calc();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    $num is not global and hence is not available for calc().


  1. What will be the output of the following PHP code ?
    <?php
    function str($Message)
    {
    $Message = ucwords($Message);
    echo lcfirst($Message);
    }
    str("this is important...");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    ucwords() changes all the first letters to capitals. lcfirst() changes first letter of a string to small.



  1. <?php
    function car()
    {
    $car = array("Jeep", "Datsun", "Lada", "spyker");
    foreach ($car as $val)
    {
    echo "$val\n";
    }
    }
    car();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    For each function causes the program to loop through each array value once.


  1. What will be the output of the following PHP code ?
    <?php
    function SumFun($number1, $number2)
    {
    $s = $number1 + $number2;
    return $s;
    }
    $return_val = SumFun(15, 45);
    echo "Returned value : " .$return_val
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Returned value : 60



  1. What will be the output of the following PHP code ?
    <?php
    function fun($str)
    {
    echo strtr("Towe Pa55", "ow5", $str);
    }
    fun("ims");
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The strtr() function translates certain characters in a string.