Home » PHP » PHP Variables » Question
  1. What will be the output of the following PHP code ?
    <?php
    $n1 = 15;
    $n2 = 18;
    function Calc()
    {
    $GLOBALS['n2'] = $GLOBALS['n1'] + $GLOBALS['n2'];
    }
    Calc();
    echo $n2;
    ?>
    1. 15
    2. 18
    3. 33
    4. Error
    5. None of these
Correct Option: C

You can access the global variable using $GLOBALS[‘globalvariablename’].



Your comments will be displayed only after manual approval.