Creating a variable with a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
juan
Forum Newbie
Posts: 3
Joined: Sun Jan 30, 2005 3:33 pm

Creating a variable with a variable

Post by juan »

I am trying to make a variable inside a loop from another variable. For example:

inside the loop I have variable $currentrow that tells me which row the loop is on

I want to make a variable named $news_[value of current row]

so when $currentrow is 5, it makes a variable $news_5.

How do I go about doing this?

Thanks,
Jon
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not use arrays?

for "dynamic" variable create read the documentatio on variable variables: http://www.php.net/manual/en/language.v ... riable.php
juan
Forum Newbie
Posts: 3
Joined: Sun Jan 30, 2005 3:33 pm

Post by juan »

Well actually I do plan on using an array, but I want

array_1
array_2
array_3

with the # according to the value of $currentrow
juan
Forum Newbie
Posts: 3
Joined: Sun Jan 30, 2005 3:33 pm

Post by juan »

Nevermind,

I just realized it would probably be easier to do an array inside an array.

Thanks for help though.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Post Reply