Home > Tips & Tricks > Variables Variable in PHP – Double Dollar ($$) Variable

Variables Variable in PHP – Double Dollar ($$) Variable

In this trick, we will learn what is variables variable in PHP or you can say double dollar ($$) or references variable.

The $x single dollar is a normal variable in PHP where x is the name of the variable and you can hold the value in this variable.

And the $$x double dollar is a reference variable that stores the value which means the $ symbol holds the value of $x and you can access it by adding the $ prefix of the original variable ($x).

Variable’s Variable in PHP – Double Dollar ($$)

Using the double dollar ($$) variable, you can access the value of other reference variables. The syntax of using the double dollar variable ($$variable) is also called the variables variable in PHP.

Let’s see how we can use it.

Output
YourBlogCoach

Here is the explanation:

  • The $original_variable variable hold the text “YourBlogCoach
  • Then $name contain the name of the variable “original_variable
  • So $$name means that the variable that has its name contained in $name and that reference is $original_variable which has the value text.

Let’s take another real-world example, which gives you a better understanding of using the double dollar reference variable in PHP.

Output
Mohit study in Computer Science

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment