PHP for loop help needed

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
webnhance
Forum Newbie
Posts: 5
Joined: Tue Feb 10, 2009 6:23 pm

PHP for loop help needed

Post by webnhance »

Hello, here is what I am trying to accomplish. I have variables being passed from a form to a different page for processing. Say these are the names of the variables in the form... variable101, variable102, variable103... variable150. I am trying to process these 50 different variables by calling them in a for loop, like so...

for ( $i=101, $i<151, $i++ ) {
echo "variable$i contains $_POST['variable{$i}']";
}

would hopefully output....

variable101 contains blahblah1 variable102 contains blahblah2 variable103 contains blahblah3 ....

But it is not working, its not trying to call variable101, variable102, variable103.

The data in the form is there if you explicitly call $variable101, $variable102... I just cannot accomplish the task using the $i, can anyone help me please? Thanks.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP for loop help needed

Post by susrisha »

Code: Select all

 
$tmp_var='variable'.$i;
echo "variable$i contains $_POST[$tmp_var]";
 
webnhance
Forum Newbie
Posts: 5
Joined: Tue Feb 10, 2009 6:23 pm

Re: PHP for loop help needed

Post by webnhance »

susrisha wrote:

Code: Select all

 
$tmp_var='variable'.$i;
echo "variable$i contains $_POST[$tmp_var]";
 
thanks, man, i'll try that, looks like it should work
bonzai
Forum Newbie
Posts: 2
Joined: Wed Feb 11, 2009 8:55 am

Re: PHP for loop help needed

Post by bonzai »

for ( $i=101, $i<151, $i++ ) {
$tmp_var='variable'.$i;
echo "variable$i contains $_POST[$tmp_var]";
}
Post Reply