用PHP自带array_multisort函数排序

<?php
 
    $data = array();
    $data[] = array('volume' => 67, 'edition' => 2);
    $data[] = array('volume' => 86, 'edition' => 1);
    $data[] = array('volume' => 85, 'edition' => 6);
    $data[] = array('volume' => 98, 'edition' => 2);
    $data[] = array('volume' => 86, 'edition' => 6);
    $data[] = array('volume' => 67, 'edition' => 7);
 
    // 取得列的列表
    foreach ($data as $key => $row)
    {
        $volume[$key]  = $row['volume'];
        $edition[$key] = $row['edition'];
    }
 
    array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
 
    print_r($data);
?>

结果:

Array
(
    [0] => Array
        (
            [volume] => 98
            [edition] => 2
        )
    [1] => Array
        (
            [volume] => 86
            [edition] => 1
        )
    [2] => Array
        (
            [volume] => 86
            [edition] => 6
        )
    [3] => Array
        (
            [volume] => 85
            [edition] => 6
        )
    [4] => Array
        (
            [volume] => 67
            [edition] => 2
        )
    [5] => Array
        (
            [volume] => 67
            [edition] => 7
        )
)

数组分割:
array_slice($arr,0,10)

http://www.jb51.net/article/48841.htm

PHP数组排序和按数量分割的更多相关文章

  1. PHP 按照指定数量分割数组

    <?php /** * 系统辅助类 * @date 2019年7月2日 * @comment * */ class SystemUtils { private static $_instance ...

  2. 【Java】List集合按数量分组

    有时候,我们需要将大的集合按指定的数量分割成若干个小集合.(比如:集合作为SQL中IN的参数,而SQL又有长度限制,所以需要分批分几次进行查询) 虽然此需求感觉不常见,但偶也写过几次类似的方法,故记录 ...

  3. ExecutorService java多线程分割list运行

    调用方法 int threadNum = 7; while(true) { List<FaceAnalyseImage> list = faceAnalyseImageMapper.sel ...

  4. jquery取元素值

    var j = 1; if (rows.length > 0) { for (var i = 0; i < rows.length; i++) { var row = rows[i]; i ...

  5. IntelliJ IDEA 2018.3 重大升级(转)

    |0前言 2018.11.28 IntelliJ IDEA 2018.3 正式版发布.对于一个忠实爱好者,迫不及待的我下载了最新版本来体验下.而且 IDEA 今年的第三次重大更新提供了不容错过的显著功 ...

  6. 好用的sublime插件以及快捷键

    管理插件:使用Ctrl+`(Esc键下方)快捷键或者通过View->Show Console菜单打开命令行 import urllib.request,os,hashlib; h = '2915 ...

  7. numpy的函数使用

    目录 注 help ,帮助 numpy.genfromtxt,导入文件 array,创建数组(1,2维数组) array,创建行列向量 numpy.shape,看numpy数据的行列信息 numpy. ...

  8. Python解释器路径寻找规则

    Python编辑器路径寻址总结 Python编程优化 这场表演邀请了三位角色:run.sh.main.py.path.sh,拍摄场地选在了 Windows -> Git Bash 群演1号 ru ...

  9. php数组排序和分割字符串

    function sortStr($str){ $ary = str_split($str); sort($ary); $len = count($ary); $arr = array(); for( ...

随机推荐

  1. 偶然发现有的IIS里的程序,连接 不上SQL Server数据库, 超时

    经查应用程序池中, 有一个启用32位应用程序,  有时打开它就能连接上SQL SERVER了.

  2. Registering Components-->Autofac registration(include constructor injection)

    https://autofaccn.readthedocs.io/en/latest/register/registration.html Registration Concepts  (有4种方式来 ...

  3. Oozie java.io.IOException: output.properties data exceeds its limit [2048]

    在使用oozie调用sqoop时,报了下边这个错 Launcher AM execution failed java.io.IOException: output.properties data ex ...

  4. MVC viewbag & viewdata

    弱类型:ViewData[""] 动态型:ViewBag dynamic ViewData 是字典型的(Dictionary),ViewBag 不再是字典的键值对结构,而是dyna ...

  5. CentOS 5 上使用yum同时安装32位和64位包的解决方法

    在centos上使用yum在线安装软件包的时候,有时候会同时安装32位和64位的包.并且在update的时候也会更新双份. 其实让yum只安装64位的包,只要在 /etc/yum.conf 中加个 e ...

  6. Treflection05_扩展习题

    1. package reflectionZ; import java.lang.reflect.Constructor; import java.lang.reflect.Method; publi ...

  7. c++中的函数对象《未完成》

    头文件: #pragma once #include<iostream> #include<vector> using namespace std; class Student ...

  8. scala LocalDateTime String 转换

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");LocalDateTime ti ...

  9. python基础7 - 函数

    1. 函数的快速体验 所谓函数,就是把 具有独立功能的代码块 组织为一个小模块,在需要的时候 调用 函数的使用包含两个步骤: 定义函数 —— 封装 独立的功能 调用函数 —— 享受 封装 的成果 函数 ...

  10. python学习笔记(xlwt/xlrd下载安装)

    python支持处理Excel 可以使用xlwt xlrd 模块 分别在https://pypi.python.org/pypi/xlwt  和 https://pypi.python.org/pyp ...