website/errors/array.duplicateKey.md
<?php declare(strict_types = 1);
$array = [
'foo' => 1,
'bar' => 2,
'foo' => 3,
];
The array literal contains duplicate keys. When an array has duplicate keys, PHP silently overwrites the earlier value with the later one. This is usually a mistake -- either the key or the value is wrong. Only the last value for the duplicate key will be preserved.
In the example above, the key 'foo' appears twice. The first value 1 will be silently overwritten by 3.
Use unique keys for each array entry:
<?php declare(strict_types = 1);
$array = [
'foo' => 1,
'bar' => 2,
- 'foo' => 3,
+ 'baz' => 3,
];
Or remove the duplicate entry if it was unintentional:
<?php declare(strict_types = 1);
$array = [
'foo' => 1,
'bar' => 2,
- 'foo' => 3,
];