3v4l.org

run code in 300+ PHP versions simultaneously
<?php $e['invalid']['key'][] = 'a123'; $e['invalid']['key'][] = 'a456'; $e['invalid']['color'][] = 'red'; $e['missing']['key'][] = 'b72'; $e['missing']['color'][] = 'blue'; $e['missing']['color'][] = 'green'; define("ERROR_LOOKUP", [ 'invalid' => [' is not a valid ', ''], 'missing' => [' is a required ', ' - other functions have dependencies on it'], ]); define("ERROR_TYPES", array_keys(ERROR_LOOKUP)); $errors = []; foreach ($e as $type => $subtypes) { if (!in_array($type, ERROR_TYPES)) { continue; } foreach ($subtypes as $subtype => $entry) { foreach ($entry as $string) { $errors[] = $string . implode($subtype, ERROR_LOOKUP[$type]); } } } echo implode("\n", $errors);
Output for 7.1.25 - 7.1.32, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
a123 is not a valid key a456 is not a valid key red is not a valid color b72 is a required key - other functions have dependencies on it blue is a required color - other functions have dependencies on it green is a required color - other functions have dependencies on it

preferences:
145.22 ms | 408 KiB | 5 Q