Skip to content

PHP code snippet – How make a variable global ?

$a = 1;
$b = 2;
function Sum(){
    global $a, $b; // allows access to vars outside of function
    $b = $a + $b;
} 

Sum();
echo $b; // output is 3
See also  How to convert a set to a list in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.