我每个人!我需要帮助...
我正在努力实现一个递归函数,可以根据各自的“项目”查尔兹,在所有的父母中增加“新”键。
我有一个看起来像这样的数组:
$tree = [
"FOLDER_1" => [
"name" => "FOLDER 1",
"new" => 0,
"items" => [
"SUB_FOLDER_1_1" => [
"name" => "SUB FOLDER 1 1',
"new" => 0,
"items" => [
"SUB_FILE_1_1_1" => [
"name" => "SUB FILE 1 1 1',
"new" => 0
],
"SUB_FILE_1_1_2" => [
"name" => "SUB FILE 1 1 2',
"new" => 1
],
]
],
"SUB_FILE_1_1" => [
"name" => "SUB FILE 1 1',
"new" => 1
]
]
],
"FOLDER_2" => [
"name" => "FOLDER 1",
"new" => 0,
"items" => [
...
],
我需要根据给定的查尔兹项目增加所有父项键“new”。
这是我需要的结果:
$tree = [
"FOLDER_1" => [
"name" => "FOLDER 1",
---
"new" => 2,
---
"items" => [
"SUB_FOLDER_1_1" => [
"name" => "SUB FOLDER 1 1',
---
"new" => 1,
---
"items" => [
"SUB_FILE_1_1_1" => [
"name" => "SUB FILE 1 1 1',
"new" => 0
],
"SUB_FILE_1_1_2" => [
"name" => "SUB FILE 1 1 2',
"new" => 1
],
]
],
"SUB_FILE_1_1" => [
"name" => "SUB FILE 1 1',
"new" => 1
]
]
],
"FOLDER_2" => [
"name" => "FOLDER 1",
"new" => 0,
"items" => [
...
],
有人有主意吗?
谢谢!
2条答案
按热度按时间5cnsuln71#
我找到了这个代码:
它可以工作,但它是在过程中,有谁知道如何使这在oop类功能的工作?
谢谢...
vwkv1x7d2#
有了给定的结构,
它将对直接子节点上的“new”条目求和,但在此之前,它将递归到每个子节点,并让它计算其“new”总和(并将其加到当前的new数目)。通过这种方式,内部数字被向上传输。
使用给定的(bugfixed)结构的代码的结果将给出以下输出,但请随意使用更大/更深的结构。