I was wondering if it’s possible to change and initialize variables in a function without passing arguments to the function. Here is what I want to achieve:
$foo = 'Lorem';
$array = array();
foobar($foo);
function foobar(){
if (strlen($foo)== 1)
$bar = 'Ipsum';
else
$array[] = 'error';
}
fubar();
function fubar(){
if (empty($fouten))
echo $bar;
}
$foois a local (uninitialized) variable inside a function. It is different from the global variable$foo($GLOBALS['foo']).You have two ways:
or by using the
$GLOBALarray …This is not really good practice though and will become a maintenance nightmare with all those side effects