3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findANeedle(string $haystack, array $needles) { foreach ($needles as $needle) { if (str_contains($haystack, $needle)) { return $needle; } } return null; } function hasANeedle(string $haystack, array $needles): bool { foreach ($needles as $needle) { if (str_contains($haystack, $needle)) { return true; } } return false; } $haystack = 'food fighters'; $needles = ['bar', 'foo']; var_export(findANeedle($haystack, $needles)); echo "\n--\n"; var_export(hasANeedle($haystack, $needles));
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
'foo' -- true

preferences:
79.02 ms | 402 KiB | 62 Q