Home » PHP » PHP Variables » Question
  1. What will be the output of the following PHP code ?
    <?php
    $t = 2;
    function calculation()
    {
    echo $GLOBALS['t'];
    $t++;
    }
    calculation();
    calculation();
    calculation();
    ?>
    1. Error
    2. 2
    3. 22
    4. 222
    5. None of these
Correct Option: D

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



Your comments will be displayed only after manual approval.