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 variable:'
Here is my code:
global $second_array;
$second_array = array();
function operatii($v) {
$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]);
}
}
I seem to be able to use the $second_array
in the for loop, but can't use it in the operatii function.
How can I solve this problem?