2

I need the variable name as string so that I can use it.

For example:

$name = "Some Name";
echo "The name of the variable that holds the name is ".findname($name);

function findname($variable) {

 //how to find the name of the variable

 return ?;
}
mrN
  • 3,734
  • 15
  • 58
  • 82
  • ... Uh, you already know it's `"name"`... – Ignacio Vazquez-Abrams Dec 12 '10 at 10:07
  • In my case the variable name is also dynamic, so I am not sure. I just gave an example to simplify things – mrN Dec 12 '10 at 10:08
  • 3
    possible duplicate of [How to get a variable name as a string in PHP?](http://stackoverflow.com/questions/255312/how-to-get-a-variable-name-as-a-string-in-php) – Gordon Dec 12 '10 at 10:15
  • Following on from Ignacio, if you can access the contents of the variable, you can get the name. If it's a dynamic variable name: `$$varname` then the name is found in `$varname` – BudgieInWA Dec 12 '10 at 10:56
  • Possible duplicate of [How to get a variable name as a string in PHP?](http://stackoverflow.com/questions/255312/how-to-get-a-variable-name-as-a-string-in-php) – wmk Jan 28 '17 at 21:46

0 Answers0