PHP array sorting

Source: Internet
Author: User
The PHP array sorting problem now has a number array, which requires the following sorting: the first is the largest of all numbers. The second is the smallest of all the remaining numbers. The third is the largest of all the remaining numbers. The fourth is the smallest of all the remaining numbers ...... In this way, the delimiter is the largest left, and the delimiter is the smallest left until the array traversal is complete. how can this logic be handled ?, PHP array sorting
Now there is an array of numbers, which requires sorting as follows:
The first one is the largest of all numbers.
The second is the smallest of all the remaining numbers.
The third is the largest of all the remaining numbers.
The fourth is the smallest of all the remaining numbers.
......
In this way, the delimiter is the largest and the delimiter is the smallest.
Until array traversal is complete

How to deal with such logic?


------ Solution --------------------
PHP code
$ Ar = range (11, 1); sort ($ ar); while ($ ar) {$ r [] = array_pop ($ ar); if ($ ar) $ r [] = array_shift ($ ar);} print_r ($ r );

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.