This article mainly introduces the PHP method for finding the maximum and minimum numbers of 10 records that are not repeated in the numeric array. it involves the use skills of array_unique and array_slice methods in php and is of great practical value, for more information, see the example in this article. Share it with you for your reference. The details are as follows:
1. the php code is as follows:
// Randomly generate an array of 10 thousand elements for ($ I = 0; $ I <10000; $ I ++) {$ ary [] = rand );} $ ary = array_unique ($ ary); // deduplicated value sort ($ ary); // ordered $ min_10 = array_slice ($ ary, 0, 10 ); // obtain the minimum 10 values $ max_10 = array_slice ($ ary,-10, 10); // obtain the maximum 10 values rsort ($ max_10 ); // Top 10 values in reverse order: echo''; Print_r ($ min_10); print_r ($ max_10); unset ($ ary, $ min_10, $ max_10 );
2. the running result is as follows:
Array ([0] => 16 [1] => 19 [2] => 22 [3] => 31 [4] => 40 [5] => 49 [6] => 71 [7] => 74 [8] => 80 [9] => 92) array ([0] => 99997 [1] => 99991 [2] => 99973 [3] => 99958 [4] => 99955 [5] => 99946 [6] => 99939 [7] => 99933 [8] => 99927 [9] => 99900)
I hope this article will help you with php programming.