3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $inputNumbers = [1,2,3,3,4,5,6,1]; $result = []; foreach($inputNumbers as $number){ if(isset($result[$number])){ $result[$number] = $result[$number] + 1; }else{ $result[$number] = 1; } } sort($result); $formatedResult = []; foreach($result as $number => $count){ $formatedResult[] = [$number,$count]; } var_dump($formatedResult);
based on ASIKC
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.1
array(6) { [0]=> array(2) { [0]=> int(0) [1]=> int(1) } [1]=> array(2) { [0]=> int(1) [1]=> int(1) } [2]=> array(2) { [0]=> int(2) [1]=> int(1) } [3]=> array(2) { [0]=> int(3) [1]=> int(1) } [4]=> array(2) { [0]=> int(4) [1]=> int(2) } [5]=> array(2) { [0]=> int(5) [1]=> int(2) } }