Answer the question
In order to leave comments, you need to log in
Why doesn't a function in php have access to external variables?
let a = 5;
function inc() {
return a;
}
console.log(inc()); // 5
$a = 5;
function inc() {
return $a;
}
if(true) {
echo $a; // 5
}
echo inc(); // undefined
Answer the question
In order to leave comments, you need to log in
According to the prophecy.
If you want the php function to see an external variable, then you need to import it into the function using
global $a;
Variable scope for full immersion
https://www.php.net/manual/en/language.variables.s...
$a = 5;
function inc() {
return $GLOBALS["a"];
}
var_dump($a); //int(5)
var_dump(inc()); //int(5)
If you just need to put devices on the map, then The Dude from Mikrotik is perfect.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question