Home >Backend Development >PHP Problem >How to find the average of a one-dimensional array in php

How to find the average of a one-dimensional array in php

藏色散人
藏色散人Original
2022-12-26 10:20:134591browse

php method to find the average of a one-dimensional array: 1. Create a new php file; 2. Create an array; 3. Use the array_sum function to sum the elements in the array; 4. Use the count function to calculate The number of array elements, and then divide the two numbers to find the average.

How to find the average of a one-dimensional array in php

The operating environment of this tutorial: windows10 system, PHP version 8.1, DELL G3 computer

How to find a one-dimensional array in php average of?

Create a new PHP file named test.php to explain how PHP finds the average of an array.

How to find the average of a one-dimensional array in php

In the test.php file, use the header() method to set the encoding format of the page to utf-8.

How to find the average of a one-dimensional array in php

In the test.php file, create an array for testing.

How to find the average of a one-dimensional array in php

In the test.php file, use the array_sum function to sum the elements in the array, then use the count function to calculate the number of array elements, and divide the two. Can be averaged.

How to find the average of a one-dimensional array in php

In the test.php file, use echo to output the average value.

How to find the average of a one-dimensional array in php

Open the test.php file in the browser to view the results.

How to find the average of a one-dimensional array in php

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to find the average of a one-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn