PHP search for a method that does not repeat the maximum and minimum 10 digits in a numeric array

Source: Internet
Author: User
Tags numeric min

This article mainly introduced PHP to find a numerical array of not repeat the largest and smallest 10 number of methods, involving PHP Array_unique and Array_slice method of using the technique, very practical value, the need for friends can refer to the

This example describes a method for PHP to find the maximum and minimum number of 10 digits in a numeric array. Share to everyone for your reference. as follows:

1. PHP code is as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12-13 A randomly generated 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 largest 10 numerical rsort ($max _10);//reverse order the largest 10 numeric echo ' <pre> '; Print_r ($min _10); Print_r ($max _10); Unset ($ary, $min _10, $max _10);

2. The results of the operation are 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 The 25 26 Array ([0] => [1] => [2] => [3] => to [4] => [5] => [6] => (7) => (8) => 9] => 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 your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.