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' => '%s is not a valid %s', 'missing' => '%s is a required %s - other functions have dependencies on it', ]); $errors = []; foreach ($e as $type => $subtypes) { if (!isset(ERROR_LOOKUP[$type])) { continue; } foreach ($subtypes as $subtype => $entry) { foreach ($entry as $string) { $errors[] = sprintf(ERROR_LOOKUP[$type], $subtype, $string); } } } echo implode("\n", $errors);

preferences:
56.09 ms | 402 KiB | 5 Q