Hi I'm having trouble figuring out a way to include if clauses within a foreach.
I'm writing a page that allows the user to see the data they entered in in the previous form before committing it to the database. They can choose to select from data thats previously been entered for different sizes, quantities, etc, as well as entering their own new options. Right now the way I have it set all of the choices appear but they are all on one row and stacked within a cell. My problem is I need it to create a new row and print $size and $side for each value.
<tr>
<td>
<?php
if(isset($_POST['var1'])) {
$var1 = $_POST['var1'];
foreach($var1 as $value) {
echo $value . "<br>";
}
}
if(isset($_POST['new_var1'])) {
$new_var1 = $_POST['new_var1'];
foreach($new_var1 as $value) {
echo $value . "<br>";
}
}
?>
</td>
<td>
<?php
if(isset($_POST['var2'])) {
$var2 = $_POST['var2'];
foreach($var2 as $value) {
echo $value . "<br>";
}
}
if(isset($_POST['new_var2'])) {
$new_var2 = $_POST['new_var2'];
foreach($new_var2 as $value) {
echo $side . "<br>";
}
}
?>
</td>
</tr>
Is there a way to inlude if statements within a foreach so I can check to see what choices are set, then cycle through all the choices at once and then include the <tr></tr> tags within the foreach? I was thinking of doing it by making multiple if statement that check each combination of isset for my variables and have foreach statements that only include the set choices but that seems very clunky and a roundabout way to do what I need.
screw_sideandscrew_sizethe same length?