ねえ、私はこれを約3日間解決しようとしてきましたが、役に立ちませんでした。
次のような 2 次元配列があります。
$testObject = array(
array(
"id"=> 1,
"parentID"=> 0,
"insuCount"=> 300,
"totalInsuCount"=> '',
"childrenCount" => ''
),
array(
"id"=> 21,
"parentID"=> 1,
"insuCount"=> 136,
"totalInsuCount"=> '',
"childrenCount" => ''
),
array(
"id"=> 52,
"parentID"=> 21,
"insuCount"=> 99,
"totalInsuCount"=> '',
"childrenCount" => ''
)
);
配列には子/親があり、insuCount、totalInsuCount、childrenCount もあります。階層の最下部から最上位の親までの issuCount を合計し、その結果を totalInsuCount に設定しようとしています。
また、私の状況の一番上の親には2人の子供がいるように、ネストされた子供もカウントされます。
したがって、基本的に私の正しい配列は次のようになります。
$testObject = array(
array(
"id"=> 1,
"parentID"=> 0,
"insuCount"=> 300,
"totalInsuCount"=> 535,
"childrenCount" => 2
),
array(
"id"=> 21,
"parentID"=> 1,
"insuCount"=> 136,
"totalInsuCount"=> 235,
"childrenCount" => 1
),
array(
"id"=> 52,
"parentID"=> 21,
"insuCount"=> 99,
"totalInsuCount"=> 300,
"childrenCount" => 0
)
);
誰もがどうやってそれを行うのか手がかりを持っています.3日間ほどそれに取り組んできましたが、今では方法がわかりません.
ありがとうございます。