Home>Article>Backend Development> How to find the total average of three arrays in php
Implementation steps: 1. Use array_sum() and " " operator to obtain the total element sum of three arrays, the syntax is "array_sum(array 1) array_sum(array 2) array_sum(array 3)"; 2. Use the count() function and the " " operator to get the total number of elements of the three arrays, the syntax is "count(array1) count(array2) count(array3)"; 3. Use the "/" operator to get the total average Number, syntax "total elements and/total number of elements".
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
In php, you can use array_sum(), The count() function and the " " and "/" operators are used to find the total average of three arrays.
Implementation idea:
First get the sum of the total elements of the three arrays
and then get The total number of elements of the three arrays
Finally, divide the sum of the total elements by the total number of elements to get the total average
Implementation steps:
Step 1: Use the array_sum() function and the " " operator to obtain the sum of the total elements of the three arrays
Use the array_sum() function to find the sum of the elements of the three arrays respectively.
Use " " to add the sum of the three elements to find the total sum of the elements.
元素总和:".(array_sum($arr1)+array_sum($arr2)+array_sum($arr3)); ?>
Step 2: Use the count() function and the " " operator to obtain the total number of elements of the three arrays
Use the count() function to find the number of elements in the three arrays respectively
Use " " to add the three element numbers Find the total number of elements
元素总个数:".(count($arr1)+count($arr2)+count($arr3)); ?>
Step 3: Use the "/" operator to get the total average
Use the "/" operator to divide the sum of the total elements by the total number of elements to obtain the total average. Syntax:
总元素和 / 总元素个数
Full sample code:
三个数组的总元素个数:".$len; $avg=$sum/$len; echo "
三个数组的总平均数:".$avg; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to find the total average of three arrays in php. For more information, please follow other related articles on the PHP Chinese website!