Complete the code to declare a basic enum named Color.
<?php
enum [1] {
case RED;
case GREEN;
case BLUE;
}
The enum name should be Color with uppercase first letter as per convention.
Complete the code to access the GREEN case of the Color enum.
<?php
$green = Color::[1];
Enum cases are accessed using uppercase names exactly as declared, so GREEN is correct.
Fix the error in the enum declaration by completing the missing keyword.
<?php
[1] Color {
case RED;
case BLUE;
}
The keyword to declare an enum in PHP is enum.
Fill both blanks to create a backed enum with string values.
<?php enum Status: [1] { case ACTIVE = [2]; case INACTIVE = 'inactive'; }
Backed enums require specifying the type like string and assigning string values like 'active'.
Fill all three blanks to iterate over enum cases and print their names.
<?php foreach (Status::[1]() as [2]) { echo [3]->name . PHP_EOL; }
Use cases() to get all enum cases, iterate with a variable like $case, and access the name property.
