我有一张如下表所示的表格:
+---------------------------------------------+
| catID | catName | parentCatID |
+---------------------------------------------+
| 1 | Toyota | NULL |
| 2 | Honda | NULL |
| 3 | Nissan | NULL |
| 4 | Corolla | 1 |
| 5 | Premio | 1 |
| 6 | Civic | 2 |
| 7 | Sunny | 3 |
| 8 | Maxima | 3 |
| 9 | Corolla Hatchback | 4 |
| 10 | Corolla Saloon | 4 |
| 11 | Corolla Saloon Hybrid | 10 |
+----------------------------------------------+
parentCatID列引用同一个表中的父catID。我想生成具有多级父子关系的PHP数组,如下所示:
Array
(
[Toyota] => Array
(
[4] => Corolla
[9] => --Corolla Hatchback
[10] => --Corolla Saloon
[11] => ----Corolla Saloon Hybrid
[5] => Premio
)
[Nissan] => Array
(
[7] => Sunny
[8] => Maxima
)
[Honda] => Array
(
[6] => Sunny
)
)
有4个级别。第3级应该在值之前有两个连字符( - ),第4级应该有四个连字符( - )以显示深度。