Variable scope (PHP)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Met het global-keyword, kun je toegang krijgen tot de 'global' waarde van variabelen. Voorbeeld:

<?php
$a = 1;
$b = 2;

function Sum()
{
    global $a, $b;   # Makes $a & $b here available

    $b = $a + $b;
} 

Sum();
echo $b;
?>

Bronnen