Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sum risk scores for each birth year
- // $birth_years is array of birth_year=>sum_of_score
- // $years_count is birth_year=>how_many_times_it_occurs
- foreach($visitors as $visitor) {
- $birth_years[$visitor['birth_year']] += $visitor['risk_score'];
- $years_count[$visitor['birth_year']]++;
- }
- // divide sums by times that year occurs to get avg
- array_walk($birth_years, function($val, $key) use($years_count) {
- error_log(print_r($key, true), 0);
- error_log(print_r($val, true), 0);
- error_log(print_r($years_count[$key], true), 0);
- $val = $val / $years_count[$key];
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement