Get the App
SLTechnology News&Howtos  ›  Development  › 

How to calculate the average value of php array

Shulou Source: shulou.com Published: 2022-05-31 18:20:50 10月03日 Update

Most people do not understand the knowledge points of this article "php Array how to find the average", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php array how to find the average" article.

Php array to find the average method: 1, use array_sum () to calculate the sum of all elements in the array, syntax "array_sum ($arr)"; 2, use count () to get the number of elements in the array, syntax "count ($arr)"; 3, use the "number of elements and / elements" statement to calculate the array average.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The method of calculating the average value of php Array

Realize the idea:

Calculate the sum of all the elements in the array

Gets the number of elements in the array, that is, the length of the array

Divide the element sum by the length of the array to calculate the average

Implementation method:

Use array_sum () to sum

Count the number of elements using count ()

Use the "/" operator to average, syntax "elements and / elements"

Implementation example:

The above is the content of this article on "how to find the average of php arrays". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Array element average number content method grammar length sum article knowledge article value most that is ideas tutorials more steps environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Xiaomi OPPO Reno MySQL