Variable to string

I'm looking for a way to covert a variable to a string. I thought I could use settype or cast or var_dump but all don't seem to convert the variable name only, so for example:-

 $varName = "hello";

 //should echo out varName
 Echo variableToString($varName);

Open in new window


I cannot see any examples, or google results as a solution, does anyone have any ideas?

Thank you in advance
tonelm54Asked:
Who is Participating?
 
tonelm54Author Commented:
Found the answer:-
 
<?php
      $my_var = 1;
      echo var_name ($my_var);
?>

Open in new window

0
 
Ray PaseurCommented:
You're kidding, right?  What is the var_name() function?
http://php.net/manual-lookup.php?pattern=var_name&scope=quickref
0
 
tonelm54Author Commented:
Found the article http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php

Hadnt tried it out, got asked about it, did some google'ing and couldnt find anything then opened a question up on the way home, then found the article on reading something else, didn't have access to anything to test it so closed the question, yet on reading further into the article he writes the function.

In defense (not that it is one) I was concerned that I couldnt find thw function on php.net but assumed that it just might have been undocumented (not that it would have been)

Apologies for any one who finds this and thinks var_name exists, ill ask a moderator to assist in modifing the questions solution
0
 
tonelm54Author Commented:
Actually opened a kinda spin off question as it didnt really fill the requirement at  Q_28356765 if anyone is reading this, which I will test out first, before accepting.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.