Variable name chanigng?

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Variable name chanigng?

Post by spacebiscuit »

Hi,

I am running a simple for loop.

I want the loop counter to be appended to the end of a variable inside my loop, is this possible. ie:

Code: Select all

for($dim_count=1; $dim_count<6; $dim_count++){
      if($vol_height_".$dim_count."){
           do some thing.....
                                    }
                                                                                                                           }
So upon each iteration the variable name which is being evaluated is $vol_height_1, then 2,3,4,5 etc.

Thanks,

Rob.
}
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Use brackets:


Code: Select all

for($dim_count=1; $dim_count<6; $dim_count++){
      if(${"${vol_height}_${dim_count}"}){
           do some thing.....
                                    }
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Many thanks - will try.

Rob.
Post Reply