I'm relatively new in PHP/Symfony, can you help me with this?
I want to create a CSS tree and print an encapsulated array which contains 6 main categories and n-child categories, structured in this way:
Every array-node contains null-key-array with main-category with name(string) --> contains the category name (1. , 1.1, 1.1.1. ) and n-arrays with sub-nodes. The tree-array is structured by name, contains 6 main-category nodes and n sub- and sub-sub-categories for each node. looks like this:
array:6 [▼
1 => array:8 [▼
"" => array:1 [▼
"mydata" => array:3 [▼
"id" => 182
"name" => "1."
"titel" => "Maincategorie"
]
]
1 => array:9 [▼
"" => array:1 [▼
"mydata" => array:3 [▼
"id" => 1
"name" => "1.1."
"titel" => "Maincategorie - subcat1"
]
]
1 => array:1 [▼
"" => array:1 [▼
"mydata" => array:3 [▼
"id" => 2
"name" => "1.1.1."
"titel" => "Mainkategorie - subcat1_2"
]
]
]
2 => array:6 [▶]
3 => array:1 [▶]
4 => array:1 [▶]
5 => array:1 [▶]
6 => array:1 [▶]
7 => array:1 [▶]
8 => array:1 [▶]
]
2 => array:7 [▶]
3 => array:10 [▶]
4 => array:4 [▶]
5 => array:17 [▶]
6 => array:6 [▶]
7 => array:5 [▶]
]
2 => array:5 [▶]
3 => array:7 [▶]
4 => array:5 [▶]
5 => array:7 [▶]
6 => array:6 [▶]
]
My questions are:
Is it possible to call a recursive function in Twig or something like a self-called macro?
Or, do I need a function to set the depth of array first in the controller? In the empty key "", what is my main-category?
What is the best solution to create a tree from an array?
Thanks a lot - Ifgenia.