3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(6,8,9,8,9,8,5,4,4,9); function Counting($array){ $freq_data = array_count_values($array); $unique_elements = array_map('intval',array_keys($freq_data)); $min_element = min($unique_elements); $max_element = max($unique_elements); $percentage_data = []; $total = count($array); for($i = $min_element; $i <= $max_element ; ++$i){ $current_percentage = isset($freq_data[$i]) ? ($freq_data[$i] / $total) : 0; $percentage_data[$i] = $i > $min_element ? $percentage_data[$i-1] + $current_percentage : $current_percentage; } uksort($percentage_data,function($a,$b){ return strnatcmp($a,$b); });// just to be sure that associative hash keys are in ascending order return $percentage_data; } print_r(Counting($array));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [4] => 0.2 [5] => 0.3 [6] => 0.4 [7] => 0.4 [8] => 0.7 [9] => 1 )

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:
115.23 ms | 405 KiB | 5 Q