<?php
// Capture the list of taste observations across analyses and phases of analysis
$taste_observations = array();
// Temporary test data for Stack Overflow Question
$taste_observations[] = [
'analyst' => 'Ken',
'phase' => 'Entrance',
'taste' => 'Sweet',
'intensity' => 1
];
$taste_observations[] = [
'analyst' => 'Ken',
'phase' => 'Entrance',
'taste' => 'Spicy',
'intensity' => 1
];
$taste_observations[] = [
'analyst' => 'Ken',
'phase' => 'Center',
'taste' => 'Sweet',
'intensity' => 2
];
$taste_observations[] = [
'analyst' => 'Bob',
'phase' => 'Entrance',
'taste' => 'Savory',
'intensity' => 1
];
$taste_observations[] = [
'analyst' => 'Bob',
'phase' => 'After',
'taste' => 'Sweet',
'intensity' => 2,
];
$taste_summary = [];
foreach($taste_observations as $taste_observation) {
$taste_summary[$taste_observation['taste']] = [
'taste' => $taste_observation['taste'],
'count' => 1 + ($taste_summary[$taste_observation['taste']]['count'] ?? 0),
'max' => max($taste_summary[$taste_observation['taste']]['max'] ?? 0, $taste_observation['intensity']),
'sum' => $taste_observation['intensity'] + ($taste_summary[$taste_observation['taste']]['sum'] ?? 0)
];
}
ksort($taste_summary);
$taste_summary = array_values($taste_summary);
print_r($taste_summary);
preferences:
24.43 ms | 407 KiB | 5 Q