How to Get Average of an Array in PHP?

03-Apr-2023

.

Admin

How to Get Average of an Array in PHP?

Hi Dev,

This post will give you an example of how to get the average of an array in PHP. I explained simply how to get the average value of an array in PHP. We will look at examples of how to find the average value of an array in PHP. This tutorial will give you a simple example of how to get the average value of a PHP array.

In this tute, we will discuss how to get the average of an array in PHP. step by step explain how to get the average value of an array in PHP. you'll learn how to find the average value of an array in PHP. Here you will learn how to get the average value of a PHP array.

Example:


index.php

<?php

//Create array variable.

$array=[1,2,5,4,3,6,7];

//Calculate the average of an array.

$average = array_sum($array)/count($array);

//Print average.

echo $average;

?>

Output:

4

I hope it could help you...

#PHP