SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Aug 3, 2006, 15:00 #1
- Join Date
- Nov 2003
- Location
- United Kingdom
- Posts
- 2,120
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using varibles in varibles. How do I do it?
How do I put to variables together to make one sort of thing.
For example; I havePHP Code:
$dbname = "games";
$ied = "1";
echo "$dbname"."$ied";
I want them joined so that I end up getting: $games1 and I can then use that as a variable if you get what I mean.Affiliate Programs Directory - Over 3,000 Programs.
----> 150+ CPA Networks | Earn upto $.75 CPM on Banner Ads
-
Aug 3, 2006, 15:06 #2
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:echo ${$dbname.$ied};
btw- most of the time an array is a much better solution than using variable variables. code that uses variable variables can become very difficult to read and debug. i generally would not recomend using them.
-
Aug 3, 2006, 15:39 #3
- Join Date
- Sep 2004
- Location
- Kelowna, BC
- Posts
- 202
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is this what you're after:
$lname = "smith";
$fname = "john";
$fullname = $fname . " " . $lname;
echo $fullname;
the . is the concatenator
-
Aug 3, 2006, 15:40 #4
- Join Date
- Nov 2003
- Location
- United Kingdom
- Posts
- 2,120
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It doesn't seem to be working for what I want.
Affiliate Programs Directory - Over 3,000 Programs.
----> 150+ CPA Networks | Earn upto $.75 CPM on Banner Ads
-
Aug 3, 2006, 15:44 #5
- Join Date
- Sep 2004
- Location
- Kelowna, BC
- Posts
- 202
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
are you getting an error message or is the display incorrect?
-
Aug 3, 2006, 15:52 #6
- Join Date
- Nov 2003
- Location
- United Kingdom
- Posts
- 2,120
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks,
I have it working now.
I had to use the following
echo ${dbname.$ied};
Instead of using echo ${$dbname.$ied};Affiliate Programs Directory - Over 3,000 Programs.
----> 150+ CPA Networks | Earn upto $.75 CPM on Banner Ads
-
Aug 3, 2006, 16:15 #7
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
works for me, unless what you asked for was not what you really meant.
PHP Code:$dbname = "games";
$ied = "1";
$games1 = 'foo';
echo ${$dbname.$ied};
-
Aug 3, 2006, 16:46 #8
- Join Date
- Jan 2002
- Location
- Australia
- Posts
- 2,634
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that seems a complex way of writing it.
PHP Code:$game = $dbname . $ied;
echo $game;
-
Aug 3, 2006, 16:52 #9
- Join Date
- Nov 2003
- Location
- United Kingdom
- Posts
- 2,120
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, I did make a little mistake. $dbname should be dbname.
Originally Posted by clamcrusher
Affiliate Programs Directory - Over 3,000 Programs.
----> 150+ CPA Networks | Earn upto $.75 CPM on Banner Ads
Bookmarks