Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Calling a variable by a variable
Old 02-02-2011, 08:09 PM Calling a variable by a variable
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
I have no idea how to do this, and I don't know why it would be helpful, but it was just one of those questions I had. Let's start with some code.

PHP Code:
//Some variables
$something_variable "something variable";
$another_variable "another variable";
$yet_another_variable "yet another variable!!"
I have 3 variables here. What if I wanted to call a variable, based on user's direct input like this, instead of using an if statement?

PHP Code:
//POST data says the user entered 'something' into a box.
//I want to echo $something_variable, because the variable's name has 'something' in it. 
How would I do that? Thanks
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-02-2011, 08:14 PM Re: Calling a variable by a variable
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You can call a var by a string:

PHP Code:
if ($varname $_GET['varname'] . '_variable' AND isset($$varname)) echo $$varname
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 02-02-2011, 08:15 PM Re: Calling a variable by a variable
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Thanks, mrgraphic!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to Calling a variable by a variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28958 seconds with 12 queries