PHP: finding the maximum and minimum numbers of 10 rows without repeating the number array _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

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.