Home  >  Article  >  Backend Development  >  Fatal error of php variable variables: Cannot use [] for reading

Fatal error of php variable variables: Cannot use [] for reading

WBOY
WBOYOriginal
2016-08-08 09:29:365158browse

<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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn