Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable in a variable

Status
Not open for further replies.

blitzer

Programmer
Jun 18, 2001
34
0
0
CA
for ($nvar = 0; $nvar < 26; $nvar++) {
if ($FORM{'$nvar'}) {
$n_variables = &quot;$n_variables|$nvar\*$FORM{'$nvar'}&quot;;
}
}

Basically I have $FORM{'1'} , $FORM{'2'} , etc.. I might want to change it to even higher than 25 so I don't want to have to repeat the code over and over. The code i've given doesn't work because $FORM{'$nvar'} is not recognised. Can someone tell me a way to do this?

Thanks,
-blitzer
 
blitzer,

Not sure what you're trying to do here, do you want to multiply $nvar by $FORM{'nvar'} and then make that part of a string?

If you do, try this expression:

&quot;$n_variables|&quot; . ($nvar * $FORM{'$nvar'}); Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Noticed you are using single-quotes around your variable. This will not interpolate as you are probably wanting it to do... change to double quotes, or none at all.

# if ($FORM{'$nvar'}) { # wrong

if( $FORM{$nvar} ){ # right


Hope this helps...

--jim
* * * Merry Christmas and Happy New Year! * * *

( Don't touch that Red Flag link you crazy freak, it's just a holiday greeting! )
 
ah... :~/ yes.... Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
I knew that would get you!
That reminds of an old study I saw once, where large flash
cards were displayed to individuals, and the cards had
common sentences on them. Basically, you were asked to
to read the card out loud.

Smart people, or atleast people who read alot, wouldn't notice that sentences (like the one above) were either mispelled, or had the same word next to each other (to to). This is becuase they didn't really read the sentence word for word, but their brain recognized and assumed structure about the sentence.

Slower people did notice the mistakes, becuase they read the lines word by word.

So I guess that you missing that simple mistake makes you smart! Uh oh... that means I'm slower. ;)

--jim * * * Merry Christmas and Happy New Year! * * *

( Don't touch that Red Flag link you crazy freak, it's just a holiday greeting! )
 
Anyway <very embarassed, and not saying how many times I had to read that>...

Blitzer -- did any of that help you? Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Thanks all! The advice given by Coderifous was what i was looking for.

-blitz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top