I have a form with multiple rows and multiple "select" drop-down menus in each row. For simplicity I am showing 2x2 in this example but in reality it could go up to 5x5.
In simplified form, my HTML form looks like this:
<form action="aaa2.php" method="post" name="book">
<?php $roomNumber=101; ?>
Normal Occupancy
<select name="occupancy[101]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Extra Beds
<select name="extrabed[101]">
<option value="1">1</option>
<option value="2">2</option>
</select>
<br><br>
<?php $roomNumber=101; ?>
Normal Occupancy
<select name="occupancy[102]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Extra Beds
<select name="extrabed[102]">
<option value="1">1</option>
<option value="2">2</option>
</select>
<br><br>
<input name="Submit" type="submit" value="submit">
</form>
On the next page, I can easily display the information from the first drop-down:
<?php
$occupancy_array=$_POST['occupancy'];
foreach($occupancy_array as $roomNumber=>$occupancy) {
echo "Room ".$roomNumber.". Normal occupancy is ".$occupancy.".<br>";
}
?>
My problem comes when I try to use the information from the second drop-down. I've got this far
<?php
$occupancy_array=$_POST['occupancy'];
$extrabed_array=$_POST['extrabed'];
foreach($occupancy_array as $roomNumber=>$occupancy) {
echo "Room ".$roomNumber.". Normal occupancy is ".$occupancy." and the room will take ".$extrabed." extra beds.<br>";
}
?>
but obviously I need another foreach line for the second array. I've tried it in series and I've tried it nested inside the first foreach, but neither works right. Is there a way that I can combine it all into one foreach? Or how should I do it?
occupancyandextrabedtogether?foreachs?$roomNumberto access extra beds. Something like$extrabed_array[$roomNumber]in yourforeach.