PHP

How to Calculate Average of Numbers in PHP1 min read

In this example, we will calculate the average of some numbers using PHP.

We will create a function called sum_numbers to find the average of numbers. We will define the parameter that allows users to enter as many numbers as they want into this function using the … operator.




In the sum_numbers function, we will use array_sum function to find the sum of the numbers. We will devide the resulting value of the count of numbers using count fuction.

Then we will use return keyword to return the avarage of numbers.

PHP Code:

Output:

Leave a Comment