# 数据排序取最大值

Hx_Moon_ 2015-08-04 02:01:17
``````
Array
(
0 => Array
(
'id' => 1,
'level' => 6,
'layer' => 1
),

'1' => Array
(
'id' => 15055,
[level] => 5,
[layer] => 2
),

'2' => Array
(
'id' => 15056,
'level' => 5,
'layer' => 3
),

'3' => Array
(
'id' => 15057,
'level' => 4,
'layer' => 4
),

'4' => Array
(
'id' => 15058,
'level' => 4,
'layer' => 5
)

)
``````

Array
(
0 => Array
(
'id' => 1,
'level' => 6,
'layer' => 1
),

'1' => Array
(
'id' => 15056,
'level' => 5,
'layer' => 3
),

'2' => Array
(
'id' => 15058,
'level' => 4,
'layer' => 5
)

)
...全文
154 5 打赏 收藏 转发到动态 举报

5 条回复

• 打赏
• 举报

[/quote] 哈哈，看错了，我以为他要排序。
xuzuning 2015-08-04
• 打赏
• 举报

xuzuning 2015-08-04
• 打赏
• 举报

``````\$a = Array
(
0 => Array
(
'id' => 1,
'level' => 6,
'layer' => 1
),

'1' => Array
(
'id' => 15055,
'level' => 5,
'layer' => 2
),

'2' => Array
(
'id' => 15056,
'level' => 5,
'layer' => 3
),

'3' => Array
(
'id' => 15057,
'level' => 4,
'layer' => 4
),

'4' => Array
(
'id' => 15058,
'level' => 4,
'layer' => 5
)

);
\$r = array();
foreach(\$a as \$v) {
if(! isset(\$r[\$v['level']])) \$r[\$v['level']] = \$v;
if(\$r[\$v['level']]['layer'] < \$v['layer']) \$r[\$v['level']] = \$v;
}
\$r = array_values(\$r);
var_export(\$r);``````
``````array (
0 =>   array (
'id' => 1,
'level' => 6,
'layer' => 1,
),
1 =>   array (
'id' => 15056,
'level' => 5,
'layer' => 3,
),
2 =>   array (
'id' => 15058,
'level' => 4,
'layer' => 5,
),
)
``````

• 打赏
• 举报

• 打赏
• 举报

21,886

• 近7日
• 近30日
• 至今