What are the potential pitfalls of using multiple GET variables with the same name in PHP, and how can they be avoided?

Using multiple GET variables with the same name in PHP can lead to unexpected behavior as PHP will only consider the last value assigned to that variable. To avoid this, you can append square brackets [] to the variable name in the HTML form to create an array of values in PHP.

<form method="GET">
    <input type="text" name="example[]">
    <input type="text" name="example[]">
    <input type="text" name="example[]">
    <input type="submit" value="Submit">
</form>

<?php
if(isset($_GET['example'])) {
    foreach($_GET['example'] as $value) {
        echo $value . "<br>";
    }
}
?>