3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foo = [1234, 4321, 3421, 2134, 468]; $bar = 21; 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);

preferences:
45.83 ms | 702 KiB | 5 Q