PHP searches for the maximum and minimum 10 numbers of arrays in the numeric array. PHP searches for the maximum number and minimum number of 10 records in the numeric array. This article describes how to search for the maximum number and minimum number of 10 records in the numeric array in PHP. Share The PHP method for finding the maximum and minimum 10 numbers of values in the numeric array. the number of arrays
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:
// 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.
Examples in 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. Share...