Need to retrieve all the names and values immediately from a backed enum (for something like a select box) and you don't want to loop over `Enum::cases()`? Try this:
<?php
enum Suit: string
{
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
public static function forSelect(): array
{
return array_combine(
array_column(self::cases(), 'value'),
array_column(self::cases(), 'name')
);
}
}
Suit::forSelect();
?>
Put `forSelect()` in a trait and use it in any enum you have that needs this functionality.