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);

preferences:
23.96 ms | 407 KiB | 5 Q