concatenation to produce series of variables

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
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

concatenation to produce series of variables

Post by bwv2 »

I want to produce a series of variables called "var1, var2, ..., var15" by using concatenation. Here is what I have so far:

Code: Select all

for($i=0; $i<=15; $i++){
$var.$i=$_POST["value_".$i.""];
}
The result is confusing. I may be doing this correctly and my problem could be elsewhere, but as of now I think this may be the issue. Anyone see anything wrong with my method of joining the two variables on line 2 of my code? Thanks.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Code: Select all

for ($i=1;$i<=15;$i++) {
  $varName = "var".$i;
  $$varName=$_POST["value_$i"];
}
Post Reply