
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to get a variable name as a string in PHP?
To get a variable name as a string in PHP, the code is as follows−
Example
<?php $a = "This is it!"; $$a = "Demo string!"; print($a); ?>
Output
This will produce the following output−
This is it!
Example
Let us now see another example −
<?php $val = "This is it!"; function display($var) { foreach($GLOBALS as $demo => $value) { if ($value === $var) { return $demo; } } return false; } print display($val); ?>
Output
This will produce the following output−
Val
- Related Articles
- How to get a variable name as a string in Python?
- How to get a function name as a string in Python?
- How to call a function from a string stored in a variable PHP?
- Get global variable dynamically by name string in JavaScript?
- How to get file name from a path in PHP?
- How to get parameters from a URL string in PHP?
- How to add a property to a JavaScript object using a variable as the name?
- How to declare a global variable in PHP?
- How to get current function name in PHP?
- How to ignore using variable name as a literal while using push() in JavaScript?
- How to get the length of longest string in a PHP array
- How to assign a PHP variable to JavaScript?
- How to print a variable name in C?
- How to use a variable in a string in jQuery?
- How to get the entire document HTML as a string in JavaScript?

Advertisements