Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
