W3docs

How to find average from array in php?

You can use the array_sum function to get the sum of all the values in an array, and then divide that sum by the number of elements in the array to get the average.

You can use the array_sum function to get the sum of all the values in an array, and then divide that sum by the number of elements in the array to get the average. For example:

Example of finding the average of an array in PHP

<?php

$numbers = [1, 2, 3, 4, 5];
$average = array_sum($numbers) / count($numbers);
echo $average;

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

This will output "3", which is the average of the numbers 1, 2, 3, 4, and 5.