Finding the average, the five smallest, and the five largest numbers in an array
There are a number of built-in functions in PHP that would make your code shorter and more direct.

The first is implode. implode takes and optional glue string and an array of values, and joins them together into a single string. So for implode(", ", array(1, "a", 3)), it would return "1, a, 3". This avoids the need to loop over the elements of an array to print them with a separator, and to catch the last case where there should be no separator.

The second is array_sum. This, as its name suggests, takes an array and sums the values. This also avoids an explicit loop.

The third is array_slice. This function will take an array, and return a portion of it based on the given parameters. It can even be used to index in reverse with a negative offset.

Putting it all together, we get the following:

&lt;?php
    echo "&lt;pre&gt;";

    $temperatures = 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);

    echo "Recorded temperatures : ";
    echo implode(", ", $temperatures);
    echo "&lt;br&gt;";

    echo "Average Temperature is : ";
    echo number_format(array_sum($temperatures) / count($temperatures), 1);
    echo "&lt;br&gt;";

    //sort the temperatures in ascending order for both of the following lists.
    sort($temperatures);

    //print the first 5 values
    echo "List of five lowest temperatures : ";
    echo implode(", ", array_slice($temperatures, 0, 5));
    echo "&lt;br&gt;"; 

    //print the last 5 values
    echo "List of five highest temperatures : ";
    echo implode(", ", array_slice($temperatures, -5, 5));
    echo "&lt;br&gt;";

    echo "&lt;/pre&gt;";
?&gt;