Today we check the difference between single dollar ($) and double dollar ($$).
Here is a most confusing question that, what is the Difference between dollar and double dollar in PHP. We all know that in PHP programming $ is used for declaring variables or when we write a variable name in PHP, use $ before that name.
First thing, in the single dollar ($) stored data is fixed while in the double dollar ($$) is changed dynamically. Variable means are changeable. With explanation variables are those things which are changeable on time.
$var: represnts a variable
$$var (variable’s variable): represents a varibale with the content of $var
Now we check the major difference between $ and $$ with the help of an example below,
Example Difference between Dollar and Double Dollar in PHP
1 2 3 4 5 6 7 8 |
<?php $var = "PHCODERTECH"; $var2 = "var"; echo $var2; ?> |
Use our PHP ONLINE EDITOR
Output: PHCODERTECH
Explanation of the single dollar ($) and double dollar ($$) Example
$$var2 => $($var2) => $var => PHPCODERTECH
The double dollar is a very useful feature of PHP where you can use for assign variable value dynamically.
Check Also:
Create Dynamically Generated Text File and Download Using JavaScript
Happy Coding..!