Technology

Get all Enum items

A simple code to add in Enum file

To get all the Enum items in an array, add this little function in the Enum file.

// Assume the Enum is about brands

public static function getAllItems(): array {
    return array_map(fn($brand) => $brand->value, self::cases());
}