Answer the question
In order to leave comments, you need to log in
How to pass an external variable to a nested function?
Hello!
Example:
$myvar = 'abc';
function a() {
global $myvar;
var_dump( $myvar );
// вывод: string(3) "abc" // переменная видна
// теперь вложенная функция
function b() {
global $myvar;
var_dump( $myvar );
// вывод: // переменная не видна
}
}
b()
see the variable $myvar
? And how to make her see this variable? Answer the question
In order to leave comments, you need to log in
Because it is necessary to forget about volzhennye functions as about a terrible dream.
As well as about global variables.
Function parameters are used to pass a variable to a function.
function a($myvar) {
var_dump( $myvar );
}
function b($myvar) {
var_dump( $myvar );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question