Create global variables : GLOBALS « Language Basics « PHP






Create global variables

 
<?php

$somevar = 15;

function addit() { 
    GLOBAL $somevar;
    $somevar++; 
    print "Somevar is $somevar";
} 
addit();

?>
  
  








Related examples in the same category

1.Set new value into GLOBALS values
2.Looping Through the $GLOBALS Array
3.$GLOBALS with property
4.Accessing Global Variables with the global Statement
5.Modifying a Variable with $GLOBALS
6.Global vs function level
7.Overriding Scope with the GLOBALS Array