All Enum Cases¶
<?php
enum e: string {
case A = 1;
case B = 2;
case C = 3;
}
print_r(e::cases());
print_r(array_column(e::cases(), 'value'));
/**
Array
(
[0] => 1
[1] => 2
[2] => 3
)
*/
print_r(array_column(e::cases(), 'name'));
/**
Array
(
[0] => A
[1] => B
[2] => C
)
*/
?>
One convenient aspect of enumerations is that they come with a full list of their cases. Call the ::cases() on any enumeration to get the full list of elements.
Then, convert this list into their scalar representation, if any, by calling array_column, with the public property value.
And it always works with the name property, to collect the names of the cases.
See Also¶
PHP Features¶
Last updated: 14 July 2026