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
As about everybody suggested, you should pass your array as function parameter. Using globals is a bad practice in major cases.
function operatii($second_array, $v) {
$var1 = $second_array[count($second_array)-1];
$var2 = $second_array[count($second_array)-2];
$rez = null;
echo $var1 . $var2 . "este?";
}
$second_array = array();
for ($i = 0; $i < count($a); $i++) {
if ($a[$i] === "+" || $a[$i] === "-" || $a[$i] === "*" || $a[$i] === "/" ) {
operatii($second_array, $a[$i]);
} else {
array_push($second_array, $a[$i]);
}
}