# Associative array syntax question?

- Thread: https://externals.io/message/40661
- Original archive: https://news-web.php.net/php.internals/40661
- Started by troels knak-nielsen on 2008-09-24T12:04:08+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #40661 — troels knak-nielsen — 2008-09-24T12:04:08+00:00

URL: https://externals.io/message/40661#40661

I just realised that his is valid PHP:

<?php
var_dump(
  array(
    'foo' => 42,
    'foo' => 53));

Producing the following output:
array(1) {
  ["foo"]=>
  int(53)
}

I can anticipate that there may be practical reasons for this
"feature", but I can't think up any scenario, where it wouldn't be a
programming error to statically declare an associative array with the
same key multiple times. Is this a bug or a known quirk? Should I file
a bug-report on it?

--
troels

---

## #40662 — Jani Taskinen — 2008-09-24T12:09:39+00:00

URL: https://externals.io/message/40661#40662 · In reply to: #40661

troels knak-nielsen wrote:
> I just realised that his is valid PHP:
> 
> <?php
> var_dump(
>   array(
>     'foo' => 42,
>     'foo' => 53));
> 
> Producing the following output:
> array(1) {
>   ["foo"]=>
>   int(53)
> }
> 
> I can anticipate that there may be practical reasons for this
> "feature", but I can't think up any scenario, where it wouldn't be a
> programming error to statically declare an associative array with the
> same key multiple times. Is this a bug or a known quirk? Should I file
> a bug-report on it?

Expected behaviour.

--Jani
