I have the data that represent hierarchical structure
|id|parent_id|data||1 |0 |cat1||2 |1 |cat2||3 |4 |cat3||4 |5 |cat4| |5 |0 |cat5|
That represent a hierarchical structure like this
1|_2|5|_4 |_3
I need to implement some function or algorithm prefirible that allowme to create a hierarchical structure and get the deep of every node according to the logic structure. i mean get this information.
|id|parent_id|data|deep||1 |0 |cat1|0 ||2 |1 |cat2|1 ||3 |4 |cat3|2 ||4 |5 |cat4|1 ||5 |0 |cat5|0 |