array_unique() And Enum

../_images/array_unique_and_enum.png

Enumerations works like normal values, most of the time. They may be used as values in arrays, but not as keys, may it be directly, or with casting.

An array of enumerations can be used with in_array(), and it works the same way, with or without the third strict parameter of the function.

On the other hand, array_unique() defaults to comparing values as strings, and enumerations can’t be converted silently to strings, even when backed as strings. To make that PHP native function work, it is necessary to use the SORT_REGULAR option as third argument, which acts as $strict in in_array().

See Also

PHP Error Messages

PHP Features