PHP 多维数组排序学习
原创
©著作权归作者所有:来自51CTO博客作者程序员kunpengku的原创作品,请联系作者获取转载授权,否则将追究法律责任
<?php
$content_a['score'] = 3;
$content_a['name'] = '3name';
$content_b['score'] = 6;
$content_b['name'] = '3name';
$list1[] = $content_a;
$list1[] = $content_b;
print_r($list1);
$content_c['score'] = 2;
$content_c['name'] = '2name';
$content_c['ccc'] = 'ccc2';
$content_d['score'] = 9;
$content_d['ddd'] = '9nameddd';
$list2[] = $content_c;
$list2[] = $content_d;
print_r($list2);
$new_list = array_merge($list1, $list2);
print_r($new_list);
foreach ($new_list as $key => $value) {
$rating[$key] = $value['score'];
}
array_multisort($rating, $new_list);
#after sort
print_r($new_list);
?>
关键是 array_multisort 这个函数的用法。
打印出$rating 这个值,就明白了。