Page 1 of 1

Variable name chanigng?

Posted: Sat Jun 18, 2005 3:10 pm
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.
}

Posted: Sat Jun 18, 2005 3:22 pm
by hawleyjr
Use brackets:


Code: Select all

for($dim_count=1; $dim_count<6; $dim_count++){
      if(${"${vol_height}_${dim_count}"}){
           do some thing.....
                                    }

Posted: Sun Jun 19, 2005 6:30 am
by spacebiscuit
Many thanks - will try.

Rob.