473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dynamic Variable Name $$var

Hello,

I need to dynamically specify the name of a variable. I just read that
$varA = "Cat";
echo $$varA;

OUTPUT: Cat

What I try to establish is somehow add a bit of text on my dynamic
variable name.
so:

$varA = "Cat";
$$varA.'Food' <------ I am not sure what should be the syntax in order
the variable name to be $CatFood

The reason I want to do that is because I take the first part of the
variable name from a Database.

Thanks.
Mar 14 '06 #1
5 14410
Angelos wrote:
Hello,

I need to dynamically specify the name of a variable. I just read that
$varA = "Cat";
echo $$varA;

OUTPUT: Cat SOrry That was wrong example;
THats a correct one;

$varA = "dog";
$$varA = "jack";
echo "Dog name is: ".$dog;
OUTPUT: Dog name is: jack
What I try to establish is somehow add a bit of text on my dynamic
variable name.
so:

$varA = "Cat";
$$varA.'Food' <------ I am not sure what should be the syntax in order
the variable name to be $CatFood

The reason I want to do that is because I take the first part of the
variable name from a Database.

Thanks.

Mar 14 '06 #2
I worked it out I think:

$a = "a";
$b = "b";
$varA = $a.$b;

$$varA = "jack";
echo "Dog name is: ".$ab;
Mar 14 '06 #3
"Angelos" <an*****@redcatmedia.net> wrote in message
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
I worked it out I think:

$a = "a";
$b = "b";
$varA = $a.$b;

$$varA = "jack";
echo "Dog name is: ".$ab;


You can also use the curly braces so you don't need to always assign a new
variable for that. Example:

$alpha = 'a';
$beta = 'b';
${$alpha.$beta} = 'all your phps are belong to us';
echo $ab;

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 14 '06 #4
> ${$alpha.$beta} = 'all your phps are belong to us';

Now THAT is funny!
Mar 14 '06 #5
Kimmo Laine wrote:
"Angelos" <an*****@redcatmedia.net> wrote in message
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
I worked it out I think:

$a = "a";
$b = "b";
$varA = $a.$b;

$$varA = "jack";
echo "Dog name is: ".$ab;

You can also use the curly braces so you don't need to always assign a new
variable for that. Example:

$alpha = 'a';
$beta = 'b';
${$alpha.$beta} = 'all your phps are belong to us';
echo $ab;

OHhh thats Great !!!
Thanks .... Much better way of doing the same thing. ;)
Mar 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
6
by: 35th Ave Media | last post by:
Hello, I have about 60+ pages that I need to insert a MAILTO: tag so people can email the page using their email client. The body of the message is going to be the URL of that page. Using ASP,...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
4
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm...
1
by: empiresolutions | last post by:
Hello fellow code junkies, I am using the "Ajax dynamic list" http://dhtmlgoodies.com/index.html?whichScript=ajax-dynamic-list and i think its the best out there. I have found a compatibility...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
4
by: Michael Munch | last post by:
Hi I want to read the value of af text-field, create dynamic, in a form. Se below a small test-site to do that (but readning fails): I use the function Test_Read for reading the value from the...
1
by: chaitanyadotcom | last post by:
As per my application i need to create tabs using iFrame dynamically. There are totally 4 buttons in my application where for each button i provide a link. Where in it will dynamically create a tab...
1
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.