-1

I have a variable generated by $_POST called $quantity,

What would be the correct way to run a loop based on the value of this variable?

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
bbowesbo
  • 885
  • 1
  • 7
  • 17
  • Depends on the content and what you want to do with it. But possibly [foreach](https://secure.php.net/manual/en/control-structures.foreach.php) or [for](https://secure.php.net/manual/en/control-structures.for.php). – Jerodev Mar 31 '17 at 14:37
  • what type of variable is $quantity? what is your end goal? – Tyler Mar 31 '17 at 14:38
  • In your form do you have `` or ``? – Yolo Mar 31 '17 at 14:40

2 Answers2

0

Well, assuming that $quantity is numerical, you can do this:

for ($c = 0; $c < $quantity; $c++) {
  //do whatever
}
junkfoodjunkie
  • 3,168
  • 1
  • 19
  • 33
0

You can do a for loop (I'm assuming you want to run some code $quantity number of times)

for ($i = 0; $i < $quantity; $i++) {
    // 
}

Just make sure to sanitize your POST data

Community
  • 1
  • 1
Madzgo
  • 104
  • 2
  • 10