'Get enum value by name stored in a string in PHP

I want to get the value of an Enum in PHP by its name. My enum is like:

enum Status : int
{
    case ACTIVE = 1;
    case REVIEWED = 2;
    // ...
}

Status::from(2) can be used to get "REVIEWED", but how can I resolve the value from the name stored in a string ?



Solution 1:[1]

To get value from the name:

enum Status : int
{
   case ACTIVE = 1;
   case REVIEWED = 2;
   // ...
}

print(Status::REVIEWED->value);

Enum documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rodny_c