Home > Backend Development > PHP Tutorial > PHP two-dimensional array sorting code_PHP tutorial

PHP two-dimensional array sorting code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 16:55:16
Original
857 people have browsed it

A simple php two-dimensional array is sorted by the elements in the second dimension. This does not affect the data. It only sorts the contents of the array. Friends in need can refer to it.

 代码如下 复制代码

$ar = array(
0 => array('a'=>5, 'b'=>3, 'c'=>3),
    1 => array('a'=>5, 'b'=>2, 'c'=>1),
    2 => array('a'=>1, 'b'=>1, 'c'=>2)
);
$a = array();
$b = array();
 
 
foreach($ar as $k=>$v) {
  $a[$k] = $v['a'];
  //$b[$k] = $v['b'];
  //$c[$k] = $v['c'];
}
 
 
 
array_multisort($a, SORT_ASC, $ar);
//array_multisort($a, SORT_DESC, $b, SORT_ASC, $ar);
 
print_r($ar);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631681.htmlTechArticleA simple php two-dimensional array is sorted by the elements in the second dimension. This does not affect the data, only the array. The content inside is sorted and friends in need can refer to it. Code...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template