$lang['profil_basic_med开发者_StackOverflow中文版eni'] = array(
1 => 'Bekâr',
2 => 'Evli',
3 => 'Nişanlı',
4 => 'İlişkide',
5 => 'Ayrılmış',
6 => 'Boşanmış'
);
$lang['profil_basic_sac'] = array(
1 => 'Normal',
2 => 'Kısa',
3 => 'Orta',
4 => 'Uzun',
5 => 'Fönlü',
6 => 'Saçsız (Dazlak)',
7 => 'Karışık/Dağınık',
8 => 'Her Zaman Bol Jöleli :)'
);
function sGetVAL($item,$valno) {
$sonuc = $lang[$item][$valno];
return $sonuc;
}
$tempVAL1 = sGetVAL('profil_basic_medeni','3'); // return null
//or
$tempVAL2 = sGetVAL('profil_basic_sac','7'); // return null
$tempVAL1
or $tempVAL2
always return null
. why ? how to fix function sGetVAL ???
Because you're using literal indexes like numeric indexes?
Because the array $lang
is not visible in function?
try this:
$tempVAL1 = sGetVAL('profil_basic_medeni',3); // return null
//or
$tempVAL2 = sGetVAL('profil_basic_sac',7); // return null
and this:
function sGetVAL($item,$valno) {
global $lang;
$sonuc = $lang[$item][$valno];
return $sonuc;
}
your array is global, but your function uses a local version of it (which is different and uninitialized).
either write global $lang
first in your function, or use $GLOBALS['lang']
to access the array.
$lang
is a global variable, that is not visible to sGetVal
. Functions can usually only see variables that they define themselves (and Superglobals like $_POST
and $_GET
).
You could use
function sGetVAL($item,$valno) {
global $lang;
$sonuc = $lang[$item][$valno];
return $sonuc;
}
but it would be better to do without global variables altogether.
The sGetVal
function can't see the array $lang
as you haven't used the global
keyword to bring it into scope. Read here.
精彩评论