PHP Functions

A function is declared with function, and its parameters and return type can carry type declarations such as array and float. PHP then checks the values when the function runs.

PHP
<?php
function average(array $values): float {
    return array_sum($values) / count($values);
}

echo average([82, 91, 76, 95]), "\n";
echo round(average([1, 2]), 1), "\n";
Read the full lesson