PHP searches for the maximum and minimum 10 numbers in the numeric array without repeating

Source: Internet
Author: User
It mainly uses built-in functions, and has tried multiple methods to quickly sort and merge data. No built-in functions can be used to process data quickly! Sort () uses quick sorting! No random array of 10 thousand elements is generated for ($ i0; $ i10000; $ I ++) {$ ary [] rand ();} $ aryarray_unique ($ ary ); distinct value sort ($ ary); sequential sorting $ min_10array_sl

It mainly uses built-in functions, and has tried multiple methods to quickly sort and merge data. No built-in functions can be used to process data quickly! Sort () uses quick sorting! No // randomly generate an array of 10 thousand elements for ($ I = 0; $ i10000; $ I ++) {$ ary [] = rand );} $ ary = array_unique ($ ary); // deduplicated value sort ($ ary); // ordered $ min_10 = array_sl

It mainly uses built-in functions, and has tried multiple methods to quickly sort and merge data. No built-in functions can be used to process data quickly! Sort () uses quick sorting! <无>
// 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);
// Run the result 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)

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.