I'm pretty new to php and I've read many times "avoid global variables" but I've not understood whether I have to follow this advice everytime or not.
I need some values (they are stored into two variables) into a function and I could put both variables as parameters:
$GVar1 = array(...); //This is a multidimensional array (over 80.000 chars in declaration)
$GVar2 = array(...);
$Result = DoMyStuff('BasicValue', $GVar1, $GVar2);
function DoMyStuff ($BasicParameter, $GV1, GV2){
//Do stuff
}
or declare variables as global into the function:
$GVar1 = array(...);
$GVar2 = array(...);
$Result = DoMyStuff('BasicValue');
function DoMyStuff ($BasicParameter){
global $GVar1;
global $GVar2;
//Do stuff
}
I would like to understand if the first way is really better .. and why?