0

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++;
}
2

3 Answers 3

1

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";
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$x = 0;
while($x <= 5) {
 $fp = $_POST["fp$x"];
 echo $fp.'<br>';
 $x++;
}

Comments

0

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>";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.