1 Replies - 628 Views - Last Post: 27 February 2009 - 02:02 AM Rate Topic: -----

#1 failtofail  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-February 09

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

Posted 27 February 2009 - 12:51 AM

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:
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: 27 February 2009 - 12:52 AM


Is This A Good Question/Topic? 0
  • +

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

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

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

Posted 27 February 2009 - 02:02 AM

Sounds like what you're wanting to work with is Variables Variables. Give that link a look :)

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 February 2009 - 02:10 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1