Home >Backend Development >PHP Tutorial >What are mutable variables in php?

What are mutable variables in php?

怪我咯
怪我咯Original
2017-06-20 09:36:032286browse

VariableVariable is a unique variable in PHP that allows the name of a variable to be dynamically changed. Sometimes it is convenient to use variable variable names. That is, the variable name of a variable can be set and used dynamically. An ordinary variable is set through declaration, for example:

<?php
$a = &#39;hello&#39;;
?>

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

<?php
$$a = &#39;world&#39;;
?>

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

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

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

<?php
echo "$a $hello";
?>

They will both output:

hello world。

The following I think it’s easier to understand! ! demo

<?
 $a="whfbbs";
 $$a=&#39;b&#39;;
 echo $whfbbs;
?>

//Output b

The above is the detailed content of What are mutable variables in php?. For more information, please follow other related articles on the PHP Chinese website!

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