PHP program to demonstrate the use of the local and global variables

bookmark

<?php
    //PHP program to access the global variable 
    //from the function.
    $NUM=10;
    function test_fun()
    {
        $NUM=20;   
        printf("<br>Local NUM : %d",$NUM);
        
        global $NUM;
        printf("<br>Global NUM : %d",$NUM);
    }
    test_fun();
?> 


Output
Local NUM : 20
Global NUM : 10