PHP searches for the maximum and minimum 10 numbers in the numeric array without repeating them. PHP: how to search for the maximum and minimum numbers of 10 records without duplicates in the numeric array This article mainly introduces the PHP method to search for the maximum and minimum numbers of 10 records without duplicates in the numeric array, the arr php method in PHP is used to search for the maximum number and the minimum number of 10 records in the numeric array without repeating.
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
This example describes how to search for the maximum number and the minimum number of 10 records in a numeric array in PHP. Share it with you for your reference. The details are as follows:
1. the php code is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Randomly generate an array of 10 thousand elements For ($ I = 0; I I <10000; $ I ++ ){ $ Ary [] = rand (1,100000 ); } $ 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); // the maximum 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:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Array ( [0] => 16 [1] => 19 [2] => 22 [3] => 31 [4] => 40 [5] => 49 [6] => 71 [7] => 74 [8] => 80 [9] => 92 ) Array ( [0] = & gt; 99997 [1] => 99991. [2] => 99973. [3] = & gt; 99958 [4] = & gt; 99955 [5] = & gt; 99946 [6] = & gt; 99939 [7] = & gt; 99933 [8] = & gt; 99927 [9] = & gt; 99900 ) |
I hope this article will help you with php programming.
This article describes how to search for the maximum number and the minimum number of 10 records in a numeric array in PHP without repeating, involving arr in php...