Hi,
I would like to know if there is a way to referer to an already instantiated variable by using a string..
for example
there is a variable named $brokerName = 'The Name';
and i have a variable names $name = 'broker';
can i get the value of $brokerName by saying echo eval("$".$name.'Name');
?
Kendall
referer to a variable from a string [SOLVED]
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
referer to a variable from a string [SOLVED]
Last edited by kendall on Fri Jan 06, 2006 10:07 am, edited 1 time in total.
Code: Select all
${$broker . 'Name'};- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
referer to a variable from a string[SOLVED]
so would it be safe to say thatJenk wrote:Lookup variable variables on php.net for more examplesCode: Select all
${$broker . 'Name'};
Code: Select all
${$name.'Name'};?The Name
i tried your solution but i dont think its working
I should mention that $name is being taken out of an array thus the value changes but referes to a already instantiated variable when combines with the string Name
Kendall
sorry....i got it to worked
Last edited by kendall on Fri Jan 06, 2006 9:49 am, edited 1 time in total.
Code: Select all
<?php
$HelloWorld = "Hiya Earth!";
$one = "Hello";
$two = "World";
echo ${$one . $two}; //outputs "Hiya Earth!";
?>