PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 309,262 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,447 people online right now. Registration is fast and FREE... Join Now!




Using a variable's content as the name of another variable?

 

Using a variable's content as the name of another variable?

failtofail

26 Feb, 2009 - 11:51 PM
Post #1

New D.I.C Head
*

Joined: 26 Feb, 2009
Posts: 1

Hello! I have recently been wondering if there was a method by I could using a variable's content as the name of another variable. A longer method of doing so could be:
CODE

if ($input == 'one') $variable = $variable_one;
if ($input == 'two') $variable = $variable_two;
if ($input == 'three') $variable = $variable_three;
...
However, I have been trying to find a way to automate this by writing something theoretically similar to the following: $variable = $variable_$input. The closest I have been able to come up with is to simply use an array for the pre-existing variables (eg. $variable[$input]), but I wanted to know if there was a method of doing this with separate variables.

This post has been edited by failtofail: 26 Feb, 2009 - 11:52 PM

User is offlineProfile CardPM
+Quote Post


Valek

RE: Using A Variable's Content As The Name Of Another Variable?

27 Feb, 2009 - 01:02 AM
Post #2

The Real SkyNet
Group Icon

Joined: 8 Nov, 2008
Posts: 627



Thanked: 43 times
Dream Kudos: 175
My Contributions
Sounds like what you're wanting to work with is Variables Variables. Give that link a look smile.gif

Of course, you could shove them all into an array and use extract() on them with the EXTR_PREFIX_ALL flag, too.

This post has been edited by Valek: 27 Feb, 2009 - 01:10 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/26/09 10:17AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month