3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = "I like cats."; $needles = ['cat' => 0, 'dog' => 1]; function earlyReturn(string $haystack, array $needles) { foreach ($needles as $needle => $value) { if (strpos($haystack, $needle) !== false) { return $value; } } throw new Exception('No needles were found in the haystack'); } try { var_export(earlyReturn($haystack, $needles)); } catch (Exception $e) { echo $e->getMessage(); }

preferences:
20.25 ms | 402 KiB | 5 Q