3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function SplitIntoGroups($array) { $toReturnArray = array(); $currentNumber = $array[0]; $currentCount = 1; for($i=1; $i <= count($array); $i++) { if($array[$i] == $currentNumber) { $currentCount++; } else { $toReturnArray[] = array($currentNumber, $currentCount); $currentNumber = $array[$i]; $currentCount = 1; } } return $toReturnArray; } $answer = SplitIntoGroups(array(1,1,1,2,2,3,3,1,1,2,2,3)); for($i=0; $i<count($answer); $i++) { echo '[' . $answer[$i][0] . '] = ' . $answer[$i][1] . '<br />'; }
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 12 in /in/NjqGF on line 9 Notice: Undefined offset: 12 in /in/NjqGF on line 16 [1] = 3<br />[2] = 2<br />[3] = 2<br />[1] = 2<br />[2] = 2<br />[3] = 1<br />
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: 12 in /in/NjqGF on line 9 Notice: Undefined index: 12 in /in/NjqGF on line 16 [1] = 3<br />[2] = 2<br />[3] = 2<br />[1] = 2<br />[2] = 2<br />[3] = 1<br />
Output for 4.3.0 - 5.2.17
Notice: Undefined offset: 12 in /in/NjqGF on line 9 Notice: Undefined offset: 12 in /in/NjqGF on line 16 [1] = 3<br />[2] = 2<br />[3] = 2<br />[1] = 2<br />[2] = 2<br />[3] = 1<br />