Home > Article > Backend Development > Fatal error of php variable variables: 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>
When executing the above program, a Fatal error: Cannot use [] for reading
will appear. Because the semantics are ambiguous, change it like this:
<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>
The above introduces the Fatal error: Cannot use [] for reading of PHP variable variables, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.