Reputation: 344
I would like to loop 5 arrays in post.
What should be the right code to display:
$_POST["fp0"]
$_POST["fp1"]
..
$_POST["fp5"]
in a loop?
$x = 0;
while($x <= 5) {
$fp = ${'_POST["fp'.$x.'"]'};
echo $fp.'<br>';
$x++;
}
Upvotes: 0
Views: 58
Reputation: 1672
0 to 5 are six numbers, so you want to loop 6 elements in an array,
this is what you want
for( $i = 0; $i <= 5; $i++ ){
echo $_POST['fp'.$i]."<br>\n";
}
Upvotes: 1
Reputation: 4116
You can do it simply by for
loop, you form must POST
values for
fp0, fp1 .... fp5
for($i = 0; $i < 5; $i++) {
$fp = $_POST['fp'.$i];
echo $fp . "<br>";
}
Upvotes: 0
Reputation: 5760
Try this:
$x = 0;
while($x <= 5) {
$fp = $_POST["fp$x"];
echo $fp.'<br>';
$x++;
}
Upvotes: 0