PHP数组排序有关问题

WBOY
Release: 2016-06-13 13:40:35
Original
979 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template