I’m new to php and I can’t understand why is it that the variable “cons” isn’t recognized by the the compiler when used inside the function “func”, in the following code:
$cons = 1;
function plusCons($num) {
return $num + $cons;
}
is it impossible to use global variables inside of a function’s scope?
In order to access global variables within a PHP function, you need to use the
globalkeyword to import the variable: