3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(670006151,670006152,670006251); function getPrefixedData($arr){ if(count($arr) == 0) return []; $longest_prefix = strval($arr[0]); foreach($arr as $val){ $val = strval($val); $len = strlen($longest_prefix); for($i=0;$i<$len;++$i){ if($longest_prefix[$i] != $val[$i]){ $longest_prefix = substr($longest_prefix,0,$i); break; } } } $res = []; $len = strlen($longest_prefix); foreach($arr as $index => $val){ if($index == 0) $res[] = $longest_prefix . substr(strval($val),$len); else $res[] = substr(strval($val),$len); } return $res; } print_r(getPrefixedData([670006151,670006152,670006251])); print_r(getPrefixedData([670006151,670006154,670006158])); print_r(getPrefixedData([670006151,670006154,670006161])); print_r(getPrefixedData([670006151,670006154,7])); print_r(getPrefixedData([8,8,8]));
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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Array ( [0] => 670006151 [1] => 152 [2] => 251 ) Array ( [0] => 670006151 [1] => 4 [2] => 8 ) Array ( [0] => 670006151 [1] => 54 [2] => 61 ) Array ( [0] => 670006151 [1] => 670006154 [2] => 7 ) Array ( [0] => 8 [1] => [2] => )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
190.61 ms | 407 KiB | 5 Q