Are there any potential pitfalls when adding a new element to an existing associative array in PHP?

When adding a new element to an existing associative array in PHP, one potential pitfall is accidentally overwriting an existing key with the new value. To avoid this issue, you can use the array_key_exists() function to check if the key already exists before adding a new element.

// Check if the key already exists before adding a new element
if (!array_key_exists($key, $array)) {
    $array[$key] = $value;
}