Home  >  Article  >  php教程  >  php二维数组排序代码

php二维数组排序代码

WBOY
WBOYOriginal
2016-06-13 10:00:38968browse

一个简单的php 二维数组按第二维 里面的元素进行排序这样不影响数据,只对数组里面的内容进行排序一下,有需要的朋友参考一下。

 代码如下 复制代码
 
$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);
Statement:
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