Home  >  Article  >  Backend Development  >  PHP数组排序有关问题

PHP数组排序有关问题

WBOY
WBOYOriginal
2016-06-13 10:11:37782browse

PHP数组排序问题
现在有一个数字数组,现在要求排序是:
第一个是所有数字中最大的
第二个是剩下所有数字中最小的
第三个是剩下所有数字中最大的
第四个是剩下所有数字中最小的
……
就这样,隔一个是剩下最大,隔一个是剩下最小
直到数组遍历完毕

这样的逻辑怎么处理?


------解决方案--------------------

PHP code
$ar = range(11, 1);sort($ar);while($ar) {  $r[] = array_pop($ar);  if($ar)    $r[] = array_shift($ar);}print_r($r);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn