I\'m trying to figure out how I can use a variable that has been set outside a function, inside a function. Is there any way of doing this? I\'ve tried to set the variable t
See http://php.net/manual/en/language.variables.scope.php for documentation. I think in your specific case you weren't getting results you want because you aren't assigning the $var + 1
operation to anything. The math is performed, and then thrown away, essentially. See below for a working example:
$var = '1';
function addOne() {
global $var;
$var = $var + 1;
return $var;
}