Use variable name as a string to get the variable name. There are many ways to solve this problem some of them are discussed below:
Method 1: Using $GLOBALS: It is used to reference all variables available in global scope. It is an associative array which contains the reference of all variables which are currently defined in the global scope.
Example: This example uses $GLOBAL reference to get the variable name as a string.
Method 2: Using $$ Operator: The $$var_name is known as reference variable where $var_name is a normal variable. The $$var_name used to refer to the variable with the name as value of the variable $var_name.
Example: This example uses $$ operator to get the variable name as a string.
- How to call PHP function from string stored in a Variable
- Converting a string variable into Boolean, Integer or Float type in Golang
- Scope of Variable in R
- How to get cookies from curl into a variable in PHP ?
- PHP | Check if a variable is a function
- ES6 | Class Variable Alternatives
- PHP | Unset Session Variable
- Atomic Variable in Golang
- SASS | negative variable value
- How to declare a global variable in PHP?
- How to print variable to the terminal in SASS ?
- Why use Question mark in TypeScript variable ?
- Variable-length argument list in PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.