Merge foreach statements?
Posted: Tue Mar 13, 2007 5:56 am
Hiya,
I have a form with 3 elements that repeat many times. The following code extracts each form element no worries.
Is there any way to merge this into one statement. All 3 will ALWAYS be present. I'm guessing I could merge the 'if' lines without an issue but how could I merge the foreach lines? Obviously I need to keep driverType1, productId1 and quantityId1 'in sync'.
Any suggestions would be greatly appreciated.
tia, Will./
I have a form with 3 elements that repeat many times. The following code extracts each form element no worries.
Is there any way to merge this into one statement. All 3 will ALWAYS be present. I'm guessing I could merge the 'if' lines without an issue but how could I merge the foreach lines? Obviously I need to keep driverType1, productId1 and quantityId1 'in sync'.
Any suggestions would be greatly appreciated.
tia, Will./
Code: Select all
echo "<hr><br> Delivery Type <br>";
if (isset($_POST['driverType']) && is_array($_POST['driverType'])) {
foreach($_POST['driverType'] as $deliveryType) {
echo $deliveryType, "<br />\n";
}
}
echo "<hr><br> Product ID <br>";
if (isset($_POST['productId']) && is_array($_POST['productId'])) {
foreach($_POST['productId'] as $productId) {
echo $productId, "<br />\n";
}
}
echo "<hr><br> Quantity <br>";
if (isset($_POST['quantityId']) && is_array($_POST['quantityId'])) {
foreach($_POST['quantityId'] as $quality) {
echo $quality, "<br />\n";
}
}