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

藏色散人
Release: 2023-03-17 17:20:02
Original
4514 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!