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

WBOY
Release: 2016-08-08 09:29:36
Original
5094 people have browsed it

<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>
Copy after login

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!