3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array1 = range('A', 'I'); $array2 = array(0 => 'A', 1 => 'B', 7 => 'H', 8 => 'I'); $size1 = count($array1); $size2 = count($array2); $hit = 0; $miss = -1; $min_size = min($size1, $size2); $array3 = array(); for($i = 0; $i < $min_size ;$i++) { if($array1[$i] === $array2[$i]) { $hit++; $miss = -1; } else { if($miss == -1) { if($hit > 0); array_push($array3, $hit); $miss = 0; array_push($array3, 0); } $hit = 0; } } if($hit > 0) array_push($array3, $hit); if($size1 != $size2) { if($miss == -1) array_push($array3,0); //Suppose array sizes are not equal and last scanned element-pair is not matched. To avoid an additional 0 } print_r($array3);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 2 in /in/nC0OV on line 14 Notice: Undefined offset: 3 in /in/nC0OV on line 14 Array ( [0] => 2 [1] => 0 )
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: 2 in /in/nC0OV on line 14 Notice: Undefined index: 3 in /in/nC0OV on line 14 Array ( [0] => 2 [1] => 0 )
Output for 4.3.0 - 5.2.17
Notice: Undefined offset: 2 in /in/nC0OV on line 14 Notice: Undefined offset: 3 in /in/nC0OV on line 14 Array ( [0] => 2 [1] => 0 )