-2

E_NOTICE : type 8 -- Undefined index: $realName -- at line 26 *这是我得到的错误。

这是我的功能

function stats($label, $realName){
global $decode;
echo ("<p>".$label.$decode['stats']['$realName']."</p>");
};

我这样称呼它:

stats("Life: ", "life");

它返回:

E_NOTICE : type 8 -- Undefined index: $realName -- at line 26
Life: 

如果我在实际代码中将 $realName 更改为 life ,它将正确输出。 示例: 寿命:56305

我究竟做错了什么?我知道这与我使用 $realName 的方式有关。

4

1 回答 1

0
echo ("<p>".$label.$decode['stats']['$realName']."</p>");

删除变量周围的单引号:

echo ("<p>".$label.$decode['stats'][$realName]."</p>");

单引号中的变量不被解析。

于 2013-06-09T16:59:52.940 回答