Maison >développement back-end >tutoriel php >php 可变变量的 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>
执行上面程序会出现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教程有兴趣的朋友有所帮助。