<?php
$temp = array(78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76, 73, 68, 62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73);

function smallestTemp($temp)
{
    sort($temp, SORT_NATURAL);
    for ($i = 0; $i < 7; $i++) {
        $smallestTemp[$i] = $temp[$i];
    }
    return implode(", ", $smallestTemp);
}

function largestTemp($temp) {
    rsort($temp, SORT_NATURAL);
    for ($i = 0; $i < 7; $i++) {
        $largestTemp[$i] = $temp[$i];
    }
    return implode(", ", $largestTemp);
}

function calcAvgTemp($temp) {
    $totalTemp = 0;
    foreach ($temp as $value) {
        $totalTemp += $value;
    }
    return round( ($totalTemp / count($temp) ), 1 );
}

echo "Average Temperature is : " . calcAvgTemp($temp);
echo "<br>";
echo "List of seven lowest temperatures : " . smallestTemp($temp);
echo "<br>";
echo "List of seven highest temperatures : " . largestTemp($temp);
