In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "php array how to remove the maximum and minimum values after the average", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "php array how to remove the maximum and minimum values after the average" it!
Methods: 1, sort the array in ascending order, and use "array_pop" and "array_shift" to remove the maximum and minimum values; 2, use "count" and "array_sum" to obtain the array length and element sum; 3, use "element and / array length" to calculate the average.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The method of finding the average after removing the maximum and minimum values of php Array
1. Remove the maximum and minimum values from the array
Use sort () to sort the array in ascending order
After sorting, the first element of the array is the minimum value, and the last element is the maximum value, which can be deleted using the array_pop () and array_shift () functions.
Array_pop (): deletes the last element in the array.
Array_shift (): deletes the first element in the array.
2. Statistics the array length and the sum of array elements after removing the maximum and minimum values.
Because the array_pop () and array_shift () functions modify the original array, you can simply use the count () function to get the length of the processed array.
$len=count ($arr); echo "the length of the processed array is:". $len
You can directly use array_sum () to get the sum of the array elements:
$sum=array_sum ($arr); echo "
The sum of the processed array elements is: ". $sum
3. Average: use "array elements and" divided by "array length"
$num=$sum/$len;echo "
The average is: ". $num
Thank you for your reading, the above is the "php array how to remove the maximum and minimum values after the average" content, after the study of this article, I believe you on the php array how to remove the maximum and minimum values after the average of this problem has a more profound experience, the specific use of the need for everyone to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.