Array ( 0 = = Array ( ' id ' = = 1, ' level ' = 6, ' layer ' = 1 ), ' 1 ' = = array ( ' id ' = = 15055, [level] = 5, [layer] = 2 ), ' 2 ' = = Array ( ' id ' =& Gt 15056, ' level ' = 5, ' Layer ' and ' 3 ' , ' 3 ' = = Array ( ' id ' = = 15057, ' Level ' = 4, ' layer ' + 4 ), ' 4 ' = = Array ( ' id ' = = 15058, ' level ' = 4,< c28/> ' layer ' = 5 ))
If level is equal, the array with the larger layer is taken
The final result is this:
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
)
)
Reply to discussion (solution)
What's the problem? Bubble up a little bit ....
You can use the Usort http://php.net/manual/zh/function.usort.php function.
$a = Array ( ' id ' = = 1, ' level ' = 6, ' layer ' = 1 ), ' 1 ' = array< c7/> ( ' id ' = = 15055, ' level ' = + 5, ' layer ' = 2 ), ' 2 ' = = Array ( ' id ' = > 15056, ' level ' = 5, ' layer ' + 3 ), ' 3 ' = = Array ( ' id ' = = 15057, ' Level ' = 4, ' layer ' and ' 4 ' , ' 4 ' = = Array ( ' id ' = = 15058, ' level ' = 4,< c28/> ' 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, ),
The landlord's array from 5 elements into 3, which can be achieved by the sort?
Post code, look!
What's the problem? Bubble up a little bit ....
You can use the Usort http://php.net/manual/zh/function.usort.php function.
The landlord's array from 5 elements into 3, which can be achieved by the sort?
Post code, look!
What's the problem? Bubble up a little bit ....
You can use the Usort http://php.net/manual/zh/function.usort.php function.
Haha, look wrong, I thought he was going to sort.