php二维数组排序有关问题 求帮忙排序
Release: 2016-06-13 10:07:47
Original
1051 people have browsed it
php二维数组排序问题 求帮忙排序 现有一数组
PHP code<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$a=array( 0=>array(3=>9), 1=>array(2=>9), 2=>array(6=>5), 3=>array(1=>15), 4=>array(2=>4),); Copy after login
需要排序变为下面这样:
PHP code<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$b=array( 0=>array(1=>15), 1=>array(3=>9), 2=>array(2=>9), 3=>array(6=>5), 4=>array(2=>4), ); Copy after login
wish you all the best!
------解决方案-------------------- PHP code$a=array( 0=>array(3=>9), 1=>array(2=>9), 2=>array(6=>5), 3=>array(1=>15), 4=>array(2=>4),);foreach($a as $v) { $r[] = current($v); $k[] = key($v);}array_multisort($r, SORT_DESC, $k, SORT_DESC, $a);print_r($a);<br><font color="#e78608">------解决方案--------------------</font><br> Copy after login
探讨
PHP code $a=array( 0=>array(3=>9), 1=>array(2=>9), 2=>array(6=>5), 3=>array(1=>15), 4=>array(2=>4), ); foreach($a as $v) { $r[] = current($v); $k[] = key($v); } ……
------解决方案-------------------- 受教了------解决方案-------------------- 我的博客里正好有一个,相比起来1楼的就是小儿科------解决方案-------------------- 不换药PHP code……usort($a, create_function('$m, $n', 'return current($m)==current($n) ? (key($m)==key($n) ? 0 : key($m)<key : current> Array ( [1] => 15 ) [1] => Array ( [3] => 9 ) [2] => Array ( [2] => 9 ) [3] => Array ( [6] => 5 ) [4] => Array ( [2] => 4 ))/**/<div class="clear">
</div></key> Copy after login
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 Articles by Author
2024-10-22 09:46:29
2024-10-13 13:53:41
2024-10-12 12:15:51
2024-10-11 22:47:31
2024-10-11 19:36:51
2024-10-11 15:50:41
2024-10-11 15:07:41
2024-10-11 14:21:21
2024-10-11 12:59:11
2024-10-11 12:17:31