2020-03-19 17:32:49 +01:00
|
|
|
# DuplicateArrayKey
|
|
|
|
|
|
|
|
Emitted when an array has a key more than once
|
|
|
|
|
|
|
|
```php
|
2020-03-21 00:13:46 +01:00
|
|
|
<?php
|
|
|
|
|
2020-03-19 17:32:49 +01:00
|
|
|
$arr = [
|
2020-03-21 15:13:11 +01:00
|
|
|
'a' => 'one',
|
|
|
|
'b' => 'two',
|
|
|
|
'c' => 'this text will be overwritten by the next line',
|
|
|
|
'c' => 'three',
|
2020-03-19 17:32:49 +01:00
|
|
|
];
|
|
|
|
```
|
2020-03-21 00:13:46 +01:00
|
|
|
|
|
|
|
## How to fix
|
|
|
|
|
|
|
|
Remove the offending duplicates:
|
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$arr = [
|
2020-03-21 15:13:11 +01:00
|
|
|
'a' => 'one',
|
|
|
|
'b' => 'two',
|
|
|
|
'c' => 'three',
|
2020-03-21 00:13:46 +01:00
|
|
|
];
|
|
|
|
```
|
|
|
|
|
2020-08-08 14:09:41 +02:00
|
|
|
The first matching `'c'` key was removed to prevent a change in behaviour (any new duplicate keys overwrite the values of previous ones).
|