PHP Variables


  1. What will be the output of the following PHP code ?
    <?php
    $p = "$Test";
    $q = "/$Example";
    echo $p,$q;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Since variables $Test and $Example is not defined we only see / as output.


  1. What will be the output of the following PHP code ?
    <?php
    $t = 2;
    function calculation()
    {
    echo $GLOBALS['t'];
    $t++;
    }
    calculation();
    calculation();
    calculation();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Every time the function is called the value of t becomes 2, therefore we get 2 on every function call.



  1. What will be the output of the following PHP code ?
    <?php
    $m = 31, 14, 15, 61;
    echo "$m";
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    In C you won’t get an error but in PHP you’ll get a syntax error.


  1. What will be the output of the following PHP code ?
    <?php
    function Res($p,$q)
    {
    $p = 7;
    $q = 8;
    $r = $p + $q / $q + $p;
    echo "$r";
    }
    Res(8, 7);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Value 8, 7 is passed to the function but that is lost because p and q are initialised to 7 and 8 inside the function. Therefore we get the given result.



  1. What will be the output of the following PHP code ?
    <?php
    $p = 6;
    $q = 5;
    function Res($p , $q )
    {
    $r = $p+$q/$q+$p;
    echo "$r";
    }
    echo $p;
    echo $q;
    echo $r;
    Res(5, 6);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    It is same as above but the value passed into the function is 5,6 and not 6,5. Therefore the difference in answer.