A simple example of how to sort a two-dimensional array in PHP

Source: Internet
Author: User
Tags array sort sort

  This article mainly introduces a simple example of how to sort two-dimensional arrays in PHP, and a friend in need can refer to the

This article introduces the use of the Array_multisort function in PHP for two-dimensional array ordering examples, there is a need for friends, refer to the bar. Following an article: Php two-dimensional array sorting custom function, today, we introduce a PHP two-dimensional array ordering example. PHP is a simple sort of two-dimensional array, mainly used for array_multisort functions. Example:   code as follows: <?php /**  * php two-dimensional array sort   * Edit www.jb51.net */      $data = array (); &NB Sp     $data [] = Array (' volume ' =>, ' Edition ' => 2);      $data [] = Array (' volume ' => 86 , ' edition ' => 1;      $data [] = Array (' volume ' =>, ' Edition ' => 6);      $data [] = Array (' volume ' =>, ' Edition ' => 2);      $data [] = Array (' volume ' =>), ' Edition ' => 6 );      $data [] = Array (' volume ' =>, ' edition ' => 7);     //Get column list     & nbsp foreach ($data as $key => $row)       {          $volume [$key]  = $row [' Vol. Ume '];          $edition [$key] = $row [' Edition '];     }      ARRAy_multisort ($volume, Sort_desc, $edition, SORT_ASC, $data);      Print_r ($data); ?>      output:   code as follows: Array     (        [0] => Array       &N Bsp     (                [volume] =>-        &NBS P       [Edition] => 2            )           [1] => Array             (                [Volume] = >                 [Edition] => 1           &NBSP ; )           [2] => Array             (      &NBS P         [volume] =>                 [Edition] => 6 &N Bsp          )           [3] => Array             (&NB Sp               [volume] =>                 [Edition] => 6            )           [4] => Array   & nbsp         (                [volume] =>     &NBS P           [Edition] => 2            )       &NBS P   [5] => Array             (                [Volume] =>                 [Edition] => 7         & nbsp  )    )         Description: Array_multisort function parameters are very flexible, you can refer to the instructions in the PHP manual, in-depth study.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.