How can PHP handle multiple form inputs with the same name using arrays?

When handling multiple form inputs with the same name in PHP, you can use arrays to capture all the values. By appending "[]" to the input name in the HTML form, PHP will automatically create an array with all the values submitted. This allows you to loop through the array and access each individual value.

<form method="post">
    <input type="text" name="input[]" />
    <input type="text" name="input[]" />
    <input type="text" name="input[]" />
    <input type="submit" />
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $inputs = $_POST["input"];
    
    foreach($inputs as $input) {
        echo $input . "<br>";
    }
}
?>