07 February 2017

PHP $$variable Double dollar sign Meaning

php
In PHP language,  $(dollar sign) is used to store variable data. $$ can be used to store variable of a variable. Data stored in $ is fixed while data stored in $$(double dollar sign) can be changed dynamically.

such as:

$a represents a variable

$$a represents a variable with the content of $a

Example:

$test = "hello world"; $a = "test"; echo $$a;


Output will be hello world

Explanation :

$$a = $($a) = $(test) = $test = hello world

Double dollar is a powerful way to programmatically create variables and assign values them.


Another Example:


$a = amount”;
$$a =1000;
echo $amount; //echo’s 1000 on screen


(If you found this article useful then share with your friends.)

No comments: