<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></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></code>
以上就介紹了php 可變變數的 Fatal error: Cannot use [] for reading,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。