首页  >  文章  >  后端开发  >  php 可变变量的 Fatal error: Cannot use [] for reading

php 可变变量的 Fatal error: Cannot use [] for reading

WBOY
WBOY原创
2016-08-08 09:29:365159浏览

<code><span><?php </span><span>$nums</span> = <span>array</span>(<span>1</span>, <span>2</span>, <span>3</span>);
<span>$arr_name</span> = <span>'nums'</span>;
<span>$$arr_name</span>[] = <span>4</span>;
print_r(<span>$nums</span>);
<span>?></span></span></code>

执行上面程序会出现Fatal error: Cannot use [] for reading,因为语义模糊,要这样改:

<code><span><?php </span><span>$nums</span> = <span>array</span>(<span>1</span>, <span>2</span>, <span>3</span>);
<span>$arr_name</span> = <span>'nums'</span>;
${<span>$arr_name</span>}[] = <span>4</span>;
print_r(<span>$nums</span>);
<span>?></span></span></code>

以上就介绍了php 可变变量的 Fatal error: Cannot use [] for reading,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn