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