<?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));
sort($unique_elements);
$percentage_data = [];
$total = count($array);
foreach($unique_elements as $index => $element){
$current_percentage = $freq_data[$element] / $total;
$percentage_data[$element] = $index > 0 ? $percentage_data[$prev_element] + $current_percentage : $current_percentage;
$prev_element = $element;
}
return $percentage_data;
}
print_r(Counting($array));
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- Array
(
[4] => 0.2
[5] => 0.3
[6] => 0.4
[8] => 0.7
[9] => 1
)
preferences:
354.06 ms | 407 KiB | 5 Q