Firstly, I would use an array for this unless I’m missing something. Having variables like $seat1
, $seat2
, etc tends to have far less utility and be far more cumbersome than using an array.
That being said, use this syntax:
for ( $counter = 1; $counter <= $aantalZitjesBestellen; $counter ++) {
$key = 'seat' . $counter;
$$key = $_POST[$key];
}
Lastly, PHP has an inbuilt function for extracting array keys into the symbol table: extract()
. extract()
has enormous potential security problems if you use it with unfiltered user input (eg $_POST
) so use with caution.