Home > Backend Development > PHP Tutorial > Explanation of '$$" in $$str in php, explanation of str in php_PHP tutorial

Explanation of '$$" in $$str in php, explanation of str in php_PHP tutorial

WBOY
Release: 2016-07-13 09:47:27
Original
1098 people have browsed it

Explanation of "$$" in $$str in php, explanation of str in php

This way of writing is called a variable variable
Sometimes variable variable names are used It is very convenient. That is to say, the variable name of a variable can be set and used dynamically. An ordinary variable is set by declaration, for example:

$a = "hello";
?>

A mutable variable gets a The value of the ordinary variable is used as the variable name of this variable variable. In the above example, hello can be used as a variable variable after using two dollar signs ($). For example:

$$a = "world";
?>

At this time, both variables are defined: the contents of $a is "hello" and the content of $hello is "world". Therefore, it can be expressed as:

echo "$a ${$a}";
?>

The following writing is more accurate and will output the same The result:

echo "$a $hello";
?>

They will all output: hello world.

To use mutable variables with arrays, an ambiguity must be resolved. This is when writing $$a[1], the parser needs to know whether it wants $a[1] as a variable, or whether it wants $$a as a variable and extracts the variable with index [1] value. The syntax to solve this problem is to use ${$a[1]} for the first case and ${$a}[1] for the second case.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1026305.htmlTechArticleExplanation of $$ in $$str in php, interpretation of str in php. This way of writing is called a variable variable. It is very convenient to use mutable variable names. That is to say, the variable name of a variable can be set dynamically...
Related labels:
str
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