デモ---サブクラスで再帰的に計算された値の少額

 

パブリック関数のデモ($フレーム)
{
{($ K => $フレームとして$フレーム)foreachの
$フレーム[$ K] [ 'allCount'] = $フレーム[ 'employeeCount']。
IF($は、フレーム[ '子供']){
$フレーム[$ K] [ '子供'] =の$ this - >デモ($フレーム[ '子供'])。
$フレーム[$ K] [ 'allCount'] + = array_sum(array_column($フレーム[$ K] [ '子供']、 'allCount'));
}
}

return $frames;
}
public function index()
{
$arr = [[
'id'=>1,
'name'=>'就是',
'employeeCount'=>10,
'children'=>[[
'id'=>1,
'name'=>'就是1',
'employeeCount'=>6,
'children'=>[[
'id'=>1,
'name'=>'就是2',
'employeeCount'=>4,
'children'=>[
],
]],
'id'=>2,
'name'=>'就是3',
'employeeCount'=>11,
'children'=>[[
'id'=>1,
'name'=>'就是3',
'employeeCount'=>0,
'children'=>[[
'id'=>1,
'name'=>'就是4',
'employeeCount'=>2,
'children'=>[[
'id'=>1,
'name'=>'就是21',
'employeeCount'=>4,
'children'=>[
],
]],
]],
]],
]],

]];
$res = $this->demo($arr);dd($res);

おすすめ

転載: www.cnblogs.com/JdsyJ/p/10954288.html