我创建了一个数组,它包含多个级别的“子”数组。
$this->project_tasks: Array
(
[0] => Array
(
[person_name] => User 1
[reports_to_id] =>
[task_id] => 1123
[task_name] => Main Task
[sub_task_id] => Array
(
[0] => Array
(
[person_name] => User 1
[reports_to_id] => 1123
[task_id] => 1124
[task_name] => sub Task 1-1
[sub_task_id] => Array
(
[0] => Array
(
[person_name] => User 1
[reports_to_id] => 1124
[task_id] => 1125
[task_name] => sub Task 1-1-1
)
)
)
[1] => Array
(
[person_name] => User 1
[reports_to_id] => 1123
[task_id] => 1127
[task_name] => sub Task 1-2
)
)
)
[1] => Array
(
[person_name] => User 1
[reports_to_id] =>
[task_id] => 1126
[task_name] => Main Task 2
)
)
创建数组没有问题,当前的问题是我如何迭代整个数据集以使其显示如下:
1123 - Main Task
1124 - sub Task 1-1
1125 - sub Task 1-1-1
1127 - sub Task 1-2
...
1126 - Main Task 2
...
etc...
我找到了 array_walk_recursive() 但它不会做包含数组的键。此外,数组结构必须不关心递归的“深度”。可能是10+级,没关系。
任何帮助是极大的赞赏。