Home >Backend Development >PHP Problem >How to find the average of a one-dimensional array in php
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.
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.
In the test.php file, use the header() method to set the encoding format of the page to utf-8.
In the test.php file, create an array for testing.
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.
In the test.php file, use echo to output the average value.
Open the test.php file in the browser to view the results.
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!