Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Variable to string

Posted on 2014-02-04
4
Medium Priority
?
300 Views
Last Modified: 2014-02-04
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
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Accepted Solution

by:
tonelm54 earned 0 total points
ID: 39833550
Found the answer:-
 
<?php
      $my_var = 1;
      echo var_name ($my_var);
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39834277
You're kidding, right?  What is the var_name() function?
http://php.net/manual-lookup.php?pattern=var_name&scope=quickref
0
 

Author Comment

by:tonelm54
ID: 39834760
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
 

Author Comment

by:tonelm54
ID: 39834774
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

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question