3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foo = [1234, 4321, 3421, 2134, 468]; $bar = 34; function arithm_search($needle, $haystack) { $needle_length = floor(log10($needle)) + 1; $div = 10 ** $needle_length; foreach ($haystack as $val) { $tmp = $val; while ($tmp > 0) { if (floor($tmp % $div) == $needle) { echo $val . PHP_EOL; break; } $tmp = floor($tmp / 10); } } } arithm_search($bar, $foo);
Output for 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
1234 3421 2134

preferences:
51.53 ms | 700 KiB | 4 Q