3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = "I like cats."; $needles = ['cat' => 0, 'dog' => 1]; function inefficient(string $haystack, array $needles) { $qualifiers = array_filter( $needles, fn($k) => strpos($haystack, $k) !== false, ARRAY_FILTER_USE_KEY ); if (!$qualifiers) { throw new Exception('No needles were found in the haystack'); } return current($qualifiers); } try { var_export(inefficient($haystack, $needles)); } catch (Exception $e) { echo $e->getMessage(); }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
0

preferences:
82.07 ms | 406 KiB | 5 Q