3v4l.org

run code in 300+ PHP versions simultaneously
<?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 );
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
RainForest is the best tire with the score: 7.3333333333333

preferences:
98.42 ms | 1644 KiB | 4 Q