This article mainly introduces how to use php to implement the judges scorecard, remove the highest score and lowest score from the input array, and calculate the average score, you can find the highest score and lowest score from the input array by selecting the sort method. Then, remove the highest score and the lowest score to obtain the average score of the contestants.
1. implementation code
<? Phpfunction fairScore (& $ arr) {// select the first step of sorting. here you only need to find the maximum and minimum values in this array, no need to sort the entire array $ minVal = $ arr [0]; $ minIndex = 0; $ maxVal = $ arr [0]; $ maxIndex = 0; $ sum = 0; for ($ I = 1; $ I
$ MaxVal) {$ maxVal = $ arr [$ I]; $ maxIndex = $ I ;}} echo "Highest score :". $ maxVal. "Min :". $ minVal."
"; For ($ I = 0; $ I
Remove the average score after the highest score and lowest score
<? PhpfairScore ($ aScore);?>
2. run
The above is all the content of this article, and I hope you will like it.