PHP - 如何构建树结构列表?
所以,我的问题是,我想构建这两个表的树:
Parent table:
+-------+---------------+
| pr_id | parent_name |
+-------+---------------+
| 1 | p |
| 2 | p_0 |
| 3 | p_0_1 |
| 4 | q |
+-------+---------------+
Child table:
+-------+---------------+---------------------------+
| ch_id | pr_id | child_name |
+-------+---------------+---------------------------+
| 1 | 1 | p_0 |
| 2 | 1 | p_1 |
| 3 | 2 | p_0_0 |
| 4 | 2 | p_0_1 |
| 5 | 3 | p_0_1_0 |
| 6 | 3 | p_0_1_1 |
| 7 | 4 | q_0 |
| 8 | 4 | q_1 |
+-------+---------------+---------------------------+
树应该看起来像这样:
- p
- p_0
- p_0_0
- p_0_1
- p_0_1_0
- p_0_1_1
- p_0
- q
任何人都可以帮我一个递归解决方案吗?