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 git.master, git.master_jit, rfc.property-hooks
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] => )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
29.01 ms | 406 KiB | 5 Q