3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum AgeRangeType { case UNSPECIFIED; // Not specified. case UNKNOWN; // Used for return value only. Represents value unknown in this version. case AGE_RANGE_18_24; // Between 18 and 24 years old. case AGE_RANGE_25_34; // Between 25 and 34 years old. case AGE_RANGE_35_44; // Between 35 and 44 years old. case AGE_RANGE_45_54; // Between 45 and 54 years old. case AGE_RANGE_55_64; // Between 55 and 64 years old. case AGE_RANGE_65_UP; // 65 years old and beyond. case AGE_RANGE_UNDETERMINED; // Undetermined age range. } $ageRanges = [ AgeRangeType::AGE_RANGE_18_24->name => ['min' => 18, 'max' => 24], AgeRangeType::AGE_RANGE_25_34->name => ['min' => 25, 'max' => 34], AgeRangeType::AGE_RANGE_35_44->name => ['min' => 35, 'max' => 44], AgeRangeType::AGE_RANGE_45_54->name => ['min' => 45, 'max' => 54], AgeRangeType::AGE_RANGE_55_64->name => ['min' => 55, 'max' => 64], AgeRangeType::AGE_RANGE_65_UP->name => ['min' => 65, 'max' => 135] ]; $min_age = 20; $max_age = 60; $result = []; foreach ($ageRanges as $enum => ['min' => $min, 'max' => $max]) { if ($max >= $min_age && $min <= $max_age) { $result[] = $enum; } elseif ($result) { break; } } var_export($result);
Output for 8.1.0 - 8.1.33, 8.2.21 - 8.2.29, 8.3.5 - 8.3.27, 8.4.1 - 8.4.14
array ( 0 => 'AGE_RANGE_18_24', 1 => 'AGE_RANGE_25_34', 2 => 'AGE_RANGE_35_44', 3 => 'AGE_RANGE_45_54', 4 => 'AGE_RANGE_55_64', )
Output for 8.0.1 - 8.0.18
Parse error: syntax error, unexpected identifier "AgeRangeType" in /in/ZjG9a on line 3
Process exited with code 255.
Output for 7.4.0 - 7.4.29
Parse error: syntax error, unexpected 'AgeRangeType' (T_STRING) in /in/ZjG9a on line 3
Process exited with code 255.

preferences:
80.38 ms | 408 KiB | 5 Q