数组

 array(11) {
[0] => array(7) {
["food_id"] => string(2) "31"
["food_name"] => string(6) "啤酒"
["food_num"] => string(2) "22"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "1"
["x"] => int(2)
}
[1] => array(7) {
["food_id"] => string(2) "32"
["food_name"] => string(6) "红酒"
["food_num"] => string(2) "24"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "2"
["x"] => int(15)
}
[2] => array(7) {
["food_id"] => string(2) "33"
["food_name"] => string(6) "白酒"
["food_num"] => string(2) "12"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "3"
["x"] => int(0)
}
[3] => array(7) {
["food_id"] => string(2) "34"
["food_name"] => string(6) "拉菲"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "4"
["x"] => int(0)
}
[4] => array(7) {
["food_id"] => string(2) "35"
["food_name"] => string(8) "88拉菲"
["food_num"] => string(2) "24"
["foods_id"] => string(1) "8"
["foods_name"] => string(6) "红酒"
["ROW_NUMBER"] => string(1) "5"
["x"] => int(12)
}
[5] => array(7) {
["food_id"] => string(2) "36"
["food_name"] => string(9) "葡萄酒"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "8"
["foods_name"] => string(6) "红酒"
["ROW_NUMBER"] => string(1) "6"
["x"] => int(0)
}
[6] => array(7) {
["food_id"] => string(2) "37"
["food_name"] => string(9) "矿泉水"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "7"
["x"] => int(0)
}
[7] => array(7) {
["food_id"] => string(2) "38"
["food_name"] => string(6) "可乐"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "8"
["x"] => int(0)
}
[8] => array(7) {
["food_id"] => string(2) "39"
["food_name"] => string(6) "雪碧"
["food_num"] => string(2) "50"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "9"
["x"] => int(50)
}
[9] => array(7) {
["food_id"] => string(2) "40"
["food_name"] => string(9) "百岁山"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(2) "10"
["x"] => int(0)
}
[10] => array(7) {
["food_id"] => string(2) "41"
["food_name"] => string(6) "冰霜"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(2) "11"
["x"] => int(0)
}
}

  方法:

 foreach ($food as $key => $row) {
$id[$key] = $row['x'];
}
array_multisort($id, SORT_DESC , $food);

  结果:

 array(11) {
[0] => array(7) {
["food_id"] => string(2) "39"
["food_name"] => string(6) "雪碧"
["food_num"] => string(2) "50"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "9"
["x"] => int(50)
}
[1] => array(7) {
["food_id"] => string(2) "32"
["food_name"] => string(6) "红酒"
["food_num"] => string(2) "24"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "2"
["x"] => int(15)
}
[2] => array(7) {
["food_id"] => string(2) "35"
["food_name"] => string(8) "88拉菲"
["food_num"] => string(2) "24"
["foods_id"] => string(1) "8"
["foods_name"] => string(6) "红酒"
["ROW_NUMBER"] => string(1) "5"
["x"] => int(12)
}
[3] => array(7) {
["food_id"] => string(2) "31"
["food_name"] => string(6) "啤酒"
["food_num"] => string(2) "22"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "1"
["x"] => int(2)
}
[4] => array(7) {
["food_id"] => string(2) "33"
["food_name"] => string(6) "白酒"
["food_num"] => string(2) "12"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "3"
["x"] => int(0)
}
[5] => array(7) {
["food_id"] => string(2) "34"
["food_name"] => string(6) "拉菲"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "4"
["x"] => int(0)
}
[6] => array(7) {
["food_id"] => string(2) "36"
["food_name"] => string(9) "葡萄酒"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "8"
["foods_name"] => string(6) "红酒"
["ROW_NUMBER"] => string(1) "6"
["x"] => int(0)
}
[7] => array(7) {
["food_id"] => string(2) "37"
["food_name"] => string(9) "矿泉水"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "7"
["x"] => int(0)
}
[8] => array(7) {
["food_id"] => string(2) "38"
["food_name"] => string(6) "可乐"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(1) "8"
["x"] => int(0)
}
[9] => array(7) {
["food_id"] => string(2) "40"
["food_name"] => string(9) "百岁山"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(2) "10"
["x"] => int(0)
}
[10] => array(7) {
["food_id"] => string(2) "41"
["food_name"] => string(6) "冰霜"
["food_num"] => string(1) "0"
["foods_id"] => string(1) "1"
["foods_name"] => string(6) "凉菜"
["ROW_NUMBER"] => string(2) "11"
["x"] => int(0)
}
}

php多维数组排序的更多相关文章

  1. JS二维数组排序组合

    需求是这样的:http://q.cnblogs.com/q/29093/ 这里简述一下: 现在有一个不确定长度的数组.比如:var temp=[["Fu","Hai&qu ...

  2. PHP二维数组排序(list_order)

    /** * 对二维数组进行排序 * 模拟 数据表记录按字段排序 * * <code> * @list_order($list, $get['orderKey'], $get['orderT ...

  3. php 二维数组排序,多维数组排序

    对2维数组或者多维数组排序是常见的问题,在php中我们有个专门的多维数组排序函数,下面简单介绍下: array_multisort(array1,sorting order, sorting type ...

  4. PHP array_multisort() 函数详解 及 二维数组排序(模拟数据表记录按字段排序)

    一.先看最简单的情况. 有两个数组: $arr1 = array(1, 9, 5); $arr2 = array(6, 2, 4); array_multisort($arr1, $arr2); pr ...

  5. php基础篇-二维数组排序 array_multisort

    原文:php基础篇-二维数组排序 array_multisort 对2维数组或者多维数组排序是常见的问题,在php中我们有个专门的多维数组排序函数,下面简单介绍下: array_multisort(a ...

  6. php 对多维数组排序array_multisort

    php 对多维数组排序array_multisort 排序顺序标志: SORT_ASC - 按照上升顺序排序 SORT_DESC - 按照下降顺序排序 排序类型标志: SORT_REGULAR - 将 ...

  7. 使用 array_multisort 对多维数组排序

    array_multisort() 函数对多个数组或多维数组进行排序. 用法详看:http://www.w3school.com.cn/php/func_array_multisort.asp 例子: ...

  8. 使用php对多维维数组排序。

    要多php的多维数组排序,可以使用php里的内置函数:array_multisort(); 语法:array_multisort(array1,sorting order,sorting type,a ...

  9. PHP二维数组排序(感谢滔哥)

    滔哥原创 /* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\|| ...

  10. PHP 二维数组排序保持键名不变

    对二维数组指定的键名排序,首先大家想到的是array_multisort函数,关于array_multisort的用法我之前也写了一篇废话不多言,我们看个实例: <?php $data = ar ...

随机推荐

  1. Python基础综合练习

    from turtle import * def draw(x): begin_fill() for i in range(5): forward(x) right(144) end_fill() d ...

  2. Linux目录结构 重要目录结构详细

    1.1 /etc/hosts ip地址与主机名(域名)的对应关系  解析主机名  ping www.baidu.com 解析成10.0.0.200 1.产品测试 2  用主机名互相访问 1.2 /et ...

  3. day057 基于对象和基于双下划线的多表查询

    单表查询和多表查询的添加与查询                   上述关系:author-authordetail是一对一的关系(外键在author上名为authors),  book-publis ...

  4. jQuery键盘敲击事件,换键的话换键码就可以

    $("body").keyup(function () { if (event.which == 13){ $("#Btn_login").trigger(&q ...

  5. layui布局器网站工具

    http://layuiout.magicalcoder.com/magicaldrag-admin/drag

  6. 基于Verilog的串口发送程序

    一.模块框图及基本思路 tx_bps_module:波特率时钟产生模块 tx_control_module:串口发送的核心控制模块 tx_module:前两个模块的组合 control_module: ...

  7. Ubuntu Server 16.04设置WiFi

    wifi :http://www.cnblogs.com/joeyupdo/p/3350463.html http://blog.csdn.net/meic51/article/details/173 ...

  8. ubuntu pip install MySQL-python mysql_config not found

    在安装 mysql-python时,会出现: sh: mysql_config: not found Traceback (most recent call last):   File "s ...

  9. Spring3(一) 控制反转(IoC)和依赖注入(DI)

    几个常用框架之间的关系 1       spring框架概述 1.1   什么是spring Spring是一个开源.轻量级的Java 开发框架.框架的主要优势之一就是其分层架构,分层架构允许使用者选 ...

  10. c语言笔记4数据的输入和输出

    数据的输入和输出 知识点一 计算机的用途:数据的输入和输出. 分类: 字符:字符输入函数getchar().字符输出函数putchar(). 格式:格式输入函数scanf().格式输出函数printf ...