<?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);
You have javascript disabled. You will not be able to edit any code.