3v4l.org

run code in 300+ PHP versions simultaneously
<?php function common_parts($data) { for ($b = 1; ; $b *= 10) { $base = intdiv($data[0], $b); $matches = array_filter($data, function ($v) use ($b, $base) { return intdiv($v, $b) != $base; }); if (count($matches) == 0) break; } $base *= $b; for ($i = 1; $i < count($data); $i++) { $data[$i] = $data[$i] - $base; } return $data; } print_r(common_parts(array(670006151,670006152,670006251))); print_r(common_parts(array(670006151,670006154,670006158))); print_r(common_parts(array(670006151,670006154,670006161)));
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
Array ( [0] => 670006151 [1] => 152 [2] => 251 ) Array ( [0] => 670006151 [1] => 4 [2] => 8 ) Array ( [0] => 670006151 [1] => 54 [2] => 61 )

preferences:
98.83 ms | 407 KiB | 5 Q