How can using identical field names in a loop affect the data being sent via POST in PHP?

Using identical field names in a loop can cause the data being sent via POST in PHP to be overwritten, resulting in only the last value being captured. To solve this issue, you can append square brackets `[]` to the field name in the HTML form to create an array of values for that field. This way, each value in the loop will be stored as an element in the array.

<form method="POST">
    <?php for($i = 0; $i < 5; $i++) : ?>
        <input type="text" name="data[]" value="">
    <?php endfor; ?>
    <button type="submit">Submit</button>
</form>

<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
    $data = $_POST["data"];
    print_r($data);
}