1
<form>
  <?php
    for($i=1; $i<=3; $i++){
       print '<input ... name="'.$until.$i.'">...
   print '<input ... name="'.$quantity.$i.'">...
}
  ?>
</form>

Is it possible with this for:

for($p=1; $p<=3; $p++){

    $until.$p = $_POST['until'.$p]; // not required
    $quantity.$p = $_POST['quantity'.$p]; // required
}

to create vars that will have these names?

$until1
$quantity1
...
$until3
$quantity3

My solution won't obviously work...

user2120569
  • 227
  • 1
  • 3
  • 9

3 Answers3

5

Use an array instead. Then you can have $until[$p] for example.

Cezary Wojcik
  • 21,745
  • 6
  • 36
  • 36
1

Use ${'until'.$p} to do exactly want you want.

zavg
  • 10,351
  • 4
  • 44
  • 67
  • Thank you! I thought about the array option, but this is what I was searching for! Can you give me some references about this? Thank you again! – user2120569 Apr 25 '13 at 22:10
  • @user2120569 To be honest, array solution suggested by others is better, but this way also exists. :) http://www.php.net/manual/en/language.variables.variable.php – zavg Apr 25 '13 at 22:14
  • i'll keep it in mind! Thank you – user2120569 Apr 25 '13 at 22:16
0

Array, most definitely. Remember, with PHP you can add elements dynamically. On an aesthetic note, "until" is a reserved word in several languages, as part of program controls (e.g., if-then-else, do-while). Consider using variable names that represent the function and/or type of data.

Shlomi
  • 1
  • 2