this is an example code to illustrate her problem.
actually the problem is in variable declaration. The first $lang variable is a global scope variable while second $lang variable reference to local scope variable.
$lang = 'bahasa melayu';
function test(){
echo $lang;
}
test();
To solve this problem you need to declare local scope variable as global.
$lang = 'bahasa melayu'; //global scope variable
function test(){
echo $lang; //local scope variable
}
test(); //return ''
others solution, you may sent variable into function parameter as an example below
$lang = 'bahasa melayu'; //global scope variable
function test(){
GLOBAL $lang; //declare $lang as a global variable
echo $lang; //reference to global scope variable
}
test(); //return 'bahasa melayu'
Happy coding ;)
$lang = 'bahasa melayu'; //global scope variable
function test($param){
echo $param;
}
test(); //return 'bahasa melayu'
0 comments:
Post a Comment