Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Any more information on what's going on here and would it be faster with a bigger or smaller array. Commented Aug 31, 2016 at 10:49
  • The double flip is going to remove duplicated values, because a key can't exist twice, otherwise it gets overwritten. If any value is duplicated and the array is flipped, the last occurrence (I assume) will be the value for the key. Commented Jan 18, 2017 at 13:42
  • In PHP 7 I've noticed flipping a multidimensional array more than once may reorder array elements unexpectedly. Commented May 31, 2017 at 2:32
  • 1
    Calling array_flip() is not stable/reliable for general use. Values that coalesce to the same string or integer value will be consolidated/lost despite not being identical. Also, since PHP4.3 (maybe earlier, I don't know), this solution will emit Warnings when values are not strings or integers. Proof Commented May 20, 2023 at 22:31