Akram
Akram

Reputation: 423

array_flip() on array with duplicate values causes elements to be lost

I have following array in PHP:

Array ( [0] => Email [1] => Email [2] => Email [3] => 
 Email [4] => Email [5] => Email [6] => Email [7] => Email ) 

when I try to flip it using array_flip, it returns only last one like [Email] => 7, However,it doesn't show rest of them. How can I fix it

Upvotes: -1

Views: 737

Answers (1)

flowfree
flowfree

Reputation: 16462

In PHP, the array cannot have duplicated keys. PHP will take the last key and discard the rest.

From the array_flip() manual:

If a value has several occurrences, the latest key will be used as its values, and all others will be lost.

Upvotes: 4

Related Questions