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 );