PHP looks up a numeric array without repeating the maximum and minimum 10 number of methods, array number
The example in this article describes how PHP finds the maximum and minimum number of 10 numbers in a numeric array. Share to everyone for your reference. Specific as follows:
1. The PHP code is as follows:
Randomly generate an array of 10,000 elements for ($i =0; $i <10000; $i + +) {$ary []=rand (1,100000);} $ary =array_unique ($ary); To repeat the value sort ($ary);//Order $min_10=array_slice ($ary, 0, 10);//Remove the smallest 10 values $max_10=array_slice ($ary,-10, 10);// Take out the maximum of 10 values Rsort ($max _10);//Reverse sort the largest 10 value echo '';p rint_r ($min _10);p rint_r ($max _10); unset ($ary, $min _10, $max _10);
2. The results of the operation are as follows:
Array ( [0] = [ 1] = [ 2] = [ 3] = [ 4] = [ 5] = [6] = = [ 7] = [ 8] = [ 9] = +) Array ( [0] = 99997 [1] = 99991 [2] = 999 [3] = 99958 [4] = 99955 [5] = 99946 [6] = 99939 [7] = = 99933 [8] => ; 99927 [9] = 99900)
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/987251.html www.bkjia.com true http://www.bkjia.com/PHPjc/987251.html techarticle PHP finds a method that does not repeat the maximum and minimum number of 10 numbers in a numeric array, the number of arrays This example describes a method in which PHP finds the maximum and minimum number of 10 numbers in a valarray. Share ...