String Expressions as Identifiers

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   String Expressions as Identifiers
warhawk911
CZ Newbie
warhawk911 has been a member for over 19 year's 19 Year Member
Gender: Male
Status: Offline
Joined: Sep 13, 2005
0.00 posts per day
Posts: 4
Points: 111
   
I know a way in Javascript to do what i need to do, but i need to do about the same thing in PHP:

String Expressions as Identifiers
The ability to build the string used as the property name can be very useful in loops and with dynamically generating web pages (server side) that have variable length content. The strings can be the result of expressions that concatenate string literals with variables

Javascript Ex:

<form name="formName" action="#">
<input type="text" name="field_1">
<input type="text" name="field_2">
<input type="text" name="field_3">
</form>
- the following loop will clear the value property of each element it turn:-

for(var c = 1;c < 4;c++){
document.forms["formName"].elements["field_"+c].value = "";

NOW, i will give a small PHP cript that would require to do the same thing, I KNOW i could use aray etc.. but i need to know how to do it this way.

$var_1 = "hi";
$var_2 = "how";
$var_3 = "are";
$var_3 = "you";

for($i=0;$i<4;$i++) {
echo $var.$i;
}

Now, echo $var.$i will not work but how to make a string from 2 sting and this will identifie the var: $var_1

Anyway i am not sure if a am clear, i have been loking everywhere on the web for this, i only find ppl that say it possible, but know one say how

Thanks for the Help
warhawk911



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum