How can PHP use foreach loop to iterate through an array of values from input fields?
When dealing with input fields in PHP, you can use a foreach loop to iterate through an array of values. This is useful when processing form data or handling multiple input fields with the same name. By looping through the array, you can access each individual value and perform any necessary operations on them.
<?php
// Assuming form data is submitted via POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Iterate through array of input field values
foreach ($_POST['input_field'] as $value) {
// Process each value as needed
echo "Value: " . $value . "<br>";
}
}
?>