时间:2021-07-01 10:21:17 帮助过:30人阅读
$aData = [
['money' => 30, 'mean'=> 10, 'twl' => 1, 'xxx' => -1, 'yyy' => -1],
['money' => 30, 'mean'=> 10, 'twl' => -1, 'xxx' => -1, 'yyy' => 1],
['money' => 10, 'mean'=> 5, 'twl' => -1, 'xxx' => 1, 'yyy' => 0],
['money' => 20, 'mean'=> 10, 'twl' => 0, 'xxx' => 1, 'yyy' => -1],
['money' => 20, 'mean'=> 10, 'twl' => 0, 'xxx' => 1, 'yyy' => -1],
['money' => 20, 'mean'=> 10, 'twl' => 0, 'xxx' => 1, 'yyy' => -1],
];
foreach($aData as $id=>$m) {
$u = array_diff_key($m, ['money' => 0, 'mean' => 0]);
arsort($u);
foreach($u as $k=>$v) {
if($v == 0) continue;
if($v == 1) {
$boss = $k;
$r[$k][] = ['id' => $id, 'out' => $m['money']];
}else {
$r[$k][] = ['id' => $id, 'out' => $m['mean'], 'boss' => $boss];
$r[$boss][] = ['id' => $id, 'in' => $m['mean'], 'boss' => $k];
}
}
}
print_r($r);
Array
(
[twl] => Array
(
[0] => Array
(
[id] => 0
[out] => 30
)
[1] => Array
(
[id] => 0
[in] => 10
[boss] => yyy
)
[2] => Array
(
[id] => 0
[in] => 10
[boss] => xxx
)
[3] => Array
(
[id] => 1
[out] => 10
[boss] => yyy
)
[4] => Array
(
[id] => 2
[out] => 5
[boss] => xxx
)
)
[yyy] => Array
(
[0] => Array
(
[id] => 0
[out] => 10
[boss] => twl
)
[1] => Array
(
[id] => 1
[out] => 30
)
[2] => Array
(
[id] => 1
[in] => 10
[boss] => xxx
)
[3] => Array
(
[id] => 1
[in] => 10
[boss] => twl
)
[4] => Array
(
[id] => 3
[out] => 10
[boss] => xxx
)
[5] => Array
(
[id] => 4
[out] => 10
[boss] => xxx
)
[6] => Array
(
[id] => 5
[out] => 10
[boss] => xxx
)
)
[xxx] => Array
(
[0] => Array
(
[id] => 0
[out] => 10
[boss] => twl
)
[1] => Array
(
[id] => 1
[out] => 10
[boss] => yyy
)
[2] => Array
(
[id] => 2
[out] => 10
)
[3] => Array
(
[id] => 2
[in] => 5
[boss] => twl
)
[4] => Array
(
[id] => 3
[out] => 20
)
[5] => Array
(
[id] => 3
[in] => 10
[boss] => yyy
)
[6] => Array
(
[id] => 4
[out] => 20
)
[7] => Array
(
[id] => 4
[in] => 10
[boss] => yyy
)
[8] => Array
(
[id] => 5
[out] => 20
)
[9] => Array
(
[id] => 5
[in] => 10
[boss] => yyy
)
)
)