zoukankan      html  css  js  c++  java
  • PHP 二位数组按照下标排序

    1.排序得内容

     1 array(6) {
     2   [0] => array(12) {
     3     [0] => string(3) "160"
     4     [1] => string(2) "30"
     5     [2] => string(1) "1"
     6     [3] => string(1) "1"
     7     [4] => string(1) "1"
     8     [5] => string(1) "1"
     9     [6] => string(1) "1"
    10     [7] => string(1) "1"
    11     [8] => string(1) "1"
    12     [9] => string(1) "1"
    13     [10] => string(1) "1"
    14     [11] => string(1) "1"
    15   }
    16   [1] => array(12) {
    17     [0] => string(3) "185"
    18     [1] => string(2) "35"
    19     [2] => string(1) "1"
    20     [3] => string(1) "1"
    21     [4] => string(1) "1"
    22     [5] => string(1) "1"
    23     [6] => string(1) "1"
    24     [7] => string(1) "1"
    25     [8] => string(1) "1"
    26     [9] => string(1) "1"
    27     [10] => string(1) "1"
    28     [11] => string(1) "1"
    29   }
    30   [2] => array(12) {
    31     [0] => string(3) "175"
    32     [1] => string(2) "33"
    33     [2] => string(1) "1"
    34     [3] => string(1) "1"
    35     [4] => string(1) "1"
    36     [5] => string(1) "1"
    37     [6] => string(1) "1"
    38     [7] => string(1) "1"
    39     [8] => string(1) "1"
    40     [9] => string(1) "1"
    41     [10] => string(1) "1"
    42     [11] => string(1) "1"
    43   }
    44   [3] => array(12) {
    45     [0] => string(3) "170"
    46     [1] => string(2) "32"
    47     [2] => string(2) "11"
    48     [3] => string(1) "1"
    49     [4] => string(1) "1"
    50     [5] => string(1) "1"
    51     [6] => string(1) "1"
    52     [7] => string(1) "1"
    53     [8] => string(1) "1"
    54     [9] => string(1) "1"
    55     [10] => string(1) "1"
    56     [11] => string(1) "1"
    57   }
    58   [4] => array(12) {
    59     [0] => string(3) "165"
    60     [1] => string(2) "31"
    61     [2] => string(2) "11"
    62     [3] => string(1) "1"
    63     [4] => string(1) "1"
    64     [5] => string(1) "1"
    65     [6] => string(1) "1"
    66     [7] => string(2) "11"
    67     [8] => string(1) "1"
    68     [9] => string(1) "1"
    69     [10] => string(1) "1"
    70     [11] => string(1) "1"
    71   }
    72   [5] => array(12) {
    73     [0] => string(3) "180"
    74     [1] => string(2) "34"
    75     [2] => string(1) "1"
    76     [3] => string(1) "1"
    77     [4] => string(1) "1"
    78     [5] => string(1) "1"
    79     [6] => string(1) "1"
    80     [7] => string(1) "1"
    81     [8] => string(1) "1"
    82     [9] => string(1) "1"
    83     [10] => string(1) "1"
    84     [11] => string(1) "1"
    85   }
    86 }

    按照里面的下标为1的排序

    2 .方法:

       $sort = array(
                    'direction' => 'SORT_ASC', //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
                    'field'     => '1', //排序字段
                );
                $arrSort = array();
                foreach($data_list AS $uniqid => $row){
                    foreach($row AS $key=>$value){
                        $arrSort[$key][$uniqid] = $value;
                    }
                }
                if($sort['direction']){
                    array_multisort($arrSort[$sort['field']], constant($sort['direction']), $data_list );
                }

    3. 结果:

     1 array(6) {
     2   [0] => array(12) {
     3     [0] => string(3) "160"
     4     [1] => string(2) "30"
     5     [2] => string(1) "1"
     6     [3] => string(1) "1"
     7     [4] => string(1) "1"
     8     [5] => string(1) "1"
     9     [6] => string(1) "1"
    10     [7] => string(1) "1"
    11     [8] => string(1) "1"
    12     [9] => string(1) "1"
    13     [10] => string(1) "1"
    14     [11] => string(1) "1"
    15   }
    16   [1] => array(12) {
    17     [0] => string(3) "165"
    18     [1] => string(2) "31"
    19     [2] => string(2) "11"
    20     [3] => string(1) "1"
    21     [4] => string(1) "1"
    22     [5] => string(1) "1"
    23     [6] => string(1) "1"
    24     [7] => string(2) "11"
    25     [8] => string(1) "1"
    26     [9] => string(1) "1"
    27     [10] => string(1) "1"
    28     [11] => string(1) "1"
    29   }
    30   [2] => array(12) {
    31     [0] => string(3) "170"
    32     [1] => string(2) "32"
    33     [2] => string(2) "11"
    34     [3] => string(1) "1"
    35     [4] => string(1) "1"
    36     [5] => string(1) "1"
    37     [6] => string(1) "1"
    38     [7] => string(1) "1"
    39     [8] => string(1) "1"
    40     [9] => string(1) "1"
    41     [10] => string(1) "1"
    42     [11] => string(1) "1"
    43   }
    44   [3] => array(12) {
    45     [0] => string(3) "175"
    46     [1] => string(2) "33"
    47     [2] => string(1) "1"
    48     [3] => string(1) "1"
    49     [4] => string(1) "1"
    50     [5] => string(1) "1"
    51     [6] => string(1) "1"
    52     [7] => string(1) "1"
    53     [8] => string(1) "1"
    54     [9] => string(1) "1"
    55     [10] => string(1) "1"
    56     [11] => string(1) "1"
    57   }
    58   [4] => array(12) {
    59     [0] => string(3) "180"
    60     [1] => string(2) "34"
    61     [2] => string(1) "1"
    62     [3] => string(1) "1"
    63     [4] => string(1) "1"
    64     [5] => string(1) "1"
    65     [6] => string(1) "1"
    66     [7] => string(1) "1"
    67     [8] => string(1) "1"
    68     [9] => string(1) "1"
    69     [10] => string(1) "1"
    70     [11] => string(1) "1"
    71   }
    72   [5] => array(12) {
    73     [0] => string(3) "185"
    74     [1] => string(2) "35"
    75     [2] => string(1) "1"
    76     [3] => string(1) "1"
    77     [4] => string(1) "1"
    78     [5] => string(1) "1"
    79     [6] => string(1) "1"
    80     [7] => string(1) "1"
    81     [8] => string(1) "1"
    82     [9] => string(1) "1"
    83     [10] => string(1) "1"
    84     [11] => string(1) "1"
    85   }
    86 }
    人生得意须尽欢,莫使金樽空对月.
  • 相关阅读:
    King's Quest
    Prince and Princess
    Strongly connected
    线性渐变--linear-gradient
    镜像渐变-radio-gradient
    宽度自适应-左右
    宽度自适应-左中右
    HTML5 视频规范简介
    SVG格式
    Html5新标签解释及用法
  • 原文地址:https://www.cnblogs.com/luojie-/p/8793826.html
Copyright © 2011-2022 走看看