Hi. I recently learned PHP and am trying to declare a global array so I can access inside a function. But I seem to be missing something because I get the error \'Undefined
For anyone else hitting this old question in a google search,
In the example the variable $second_array was declared a global, not the array created in the following line. To avoid this make sure the global declaration comes after the array declaration. My preference is to put global declaration in the function itself.
$second_array = array();
function operatii($v) {
global $second_array;
$var1 = $second_array[count($second_array)-1];
$var2 = $second_array[count($second_array)-2];
$rez = null;
echo $var1 . $var2 . "este?";
}
for ($i = 0; $i < count($a); $i++){
if ($a[$i] === "+" || $a[$i] === "-" || $a[$i] === "*" || $a[$i] === "/" ) {
operatii($a[$i]);
} else {
array_push($second_array, $a[$i]);
}
}