To compute the average of a set of numbers in PHP, you can use the array_sum()
and count()
functions in combination. Here's an example:
main.php150 chars6 lines
In this example, we have an array of numbers and we use array_sum()
to calculate the sum of the array. We also use count()
to get the number of elements in the array. Then we divide the sum by the count to get the average.
The output of this code will be:
main.php18 chars2 lines
gistlibby LogSnag