What are the common pitfalls when dealing with arrays that have duplicate field names?

When dealing with arrays that have duplicate field names, the common pitfall is that accessing the values of these fields can be ambiguous and lead to unexpected results. To avoid this issue, you can use associative arrays where the field names are unique keys, or you can iterate through the array and handle duplicate field names accordingly.

// Example of handling arrays with duplicate field names
$array = [
    ['name' => 'John', 'age' => 25],
    ['name' => 'Jane', 'age' => 30],
    ['name' => 'Alice', 'age' => 28]
];

foreach ($array as $item) {
    echo "Name: " . $item['name'] . ", Age: " . $item['age'] . "\n";
}