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(); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
0

preferences:
109.53 ms | 402 KiB | 61 Q