Answer the question
In order to leave comments, you need to log in
How can a function import a variable into the current symbol table, but not into the global one?
<?php
//Это пример:
//Уровень первый, глобальный
ch_frst_lvl_var(){
$GLOBALS['lvl_1']='false';
}
$lvl_1='true';
ch_frst_lvl_var();
echo 'lvl_1: '.$lvl_1;
//Выводит "lvl_1: false"
//Это задача:
//Уровень второй, внутри функции
ch_scnd_lvl_var(){
$lvl_2='false';
//Что здесь надо дописать, чтоб функция foo() вывела "lvl_2: false" ?
}
function foo(){
$lvl_2='true';
ch_scnd_lvl_var();
echo 'lvl_2: '.$lvl_2;
}
foo();
//Выводит "lvl_2: true", а надо "lvl_2: false"
?>
Answer the question
In order to leave comments, you need to log in
<?php
function ch_scnd_lvl_var(&$var)
{
$var = 'false';
}
function foo()
{
$lvl_2 = 'true';
ch_scnd_lvl_var($lvl_2);
echo 'lvl_2: ' . $lvl_2;
}
foo();
?>
Elementary Watson!
function ch_scnd_lvl_var()
{
$lvl_2 = 'false';
echo 'lvl_2: '.$lvl_2;
die();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question