I've two tables that I've to combine to one hierarchical tree.
Table 1: Code structure
+--------+-------------+
| Code | Description |
+--------+-------------+
| A | Descr 1 |
| A1 | Descr 2 |
| A101 | Descr 3 |
| B | Descr 4 |
| B2 | Descr 5 |
| B202 | Descr 6 |
| B20201 | Descr 7 |
+--------+-------------+
Table 2: Costs
+--------+-------------+------------+
| Code | Description | Cost total |
+--------+-------------+------------+
| A101 | Cost 1 | 10000 |
| B20201 | Cost 2 | 20000 |
+--------+-------------+------------+
The challenge for me is to get the folowing output:
A Descr 1
--A1 Descr 2
----A101 Descr 3
------A101 Cost 1 10000
B - Descr 4
--B2 Descr 5
----B202 Descr 6
------B20201 Descr 7
--------B20201 Cost 1 20000
How can I create such a hierarchial list? Can someone point me in the right direction?
The main problem for me is to create a multidimensional array from the list of codes (A, A1, A101, etc.).