<?php enum Language: int { case English = 1; case SPANISH = 2; public static function getLanguageKey(string $language): int { $reflection = new \ReflectionEnum(Language::class); return $reflection->getCase($language)->getValue()->value; } public static function getLanguageName(int $languageKey): string { $reflection = new \ReflectionEnum(Language::class); $case = array_filter($reflection->getCases(), fn($enum) => $enum->getValue()->value === $languageKey); return $case[0]->getValue()->name; } } $input = 1; Language::getLanguageName($input); // 'English $input = 'English'; Language::getLanguageKey($input); // '1
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`