<?php $tires = [ 'Desert'=>array('dry'=>10, 'wet'=>4, 'snow'=>1), 'Ocean'=>array('dry'=>6, 'wet'=>8, 'snow'=>6), 'RainForest'=>array('dry'=>6, 'wet'=>10, 'snow'=>6), 'Glacier'=>array('dry'=>4, 'wet'=>9, 'snow'=>10), 'Prairie'=>array('dry'=>7, 'wet'=>7, 'snow'=>7), ]; $minimumScore = 5; // remove tires that have a single rating less than minimum $filtered = array_filter($tires, function (array $data) use ($minimumScore) { return min($data) >= $minimumScore; }); // calculate scores as average of score per category $scores = array_map(function (array $data) { return array_sum($data) / count($data); }, $filtered); // find maximum of scores $bestScore = max($scores); // find keys with the best score $bestTires = array_keys($scores, $bestScore); // there could be more than one tire with same score, pick the first $bestTire = array_shift($bestTires); echo sprintf( '%s is the best tire with the score: %s', $bestTire, $bestScore );
You have javascript disabled. You will not be able to edit any code.