My dilemma:
Once the form gets submitted, and comes through to the target php file, I have this variable problem.. the values being passed from the form are called name1, name2, name3 and so on.. a bunch..
is there a way to reference them other then typing out name1, name2 etc.
ie. something like $name = $_POST['name']; where I can just use loops to assign the variables.. the example I gave on the line above doesn't work for me. Where i is 1,2,3,4,5 and so on from a loop counter
$name = $_POST['name'];
$name1 = $_POST['name2'];
$name2 = $_POST['name3'];
is what i've been doing, but I can't do it because there's too many, a loop would work if I could reference inside the brackets with a counter like "i"
any help would be appreciated
POST- Passing to a variable on the other side
Moderator: General Moderators
- Templeton Peck
- Forum Commoner
- Posts: 45
- Joined: Sun May 11, 2003 7:51 pm
it doesn't matter how the key has been created, php takes the argument to whatever the expression evaluates.
Code: Select all
<?php
$array['name'] = 1; // a string literal passed, php is looking for a key that equals to that string
$key = 'name1';
$array[$key] = 1; // same procedure, this time not a literal but a variable holding a string
$key = 'name' . '1';
$array[$key] = 1; // key came into existence in a different way (slightly), but exactly the same lookup
$array['name'.'1'] = 1; // can be done within [ ], too
for ($i=0; $i!=10; $i++)
$array['name'.$i] = 1; // that's probably, what you want.
?>
Last edited by volka on Sun May 11, 2003 8:52 pm, edited 1 time in total.
- Templeton Peck
- Forum Commoner
- Posts: 45
- Joined: Sun May 11, 2003 7:51 pm