Skip to content
Advertisement

php tree get list of all parents of child node

I want a list of all parents of the child node. I am searching but I am getting all child nodes of the parent. my array look like

JavaScript

enter image description here

and my desired output is, I give input the child node Id and It will return all the parents. for example I will give child ID ‘raja’ and It will give output 1) manish 2) vijay 3) admin.

Advertisement

Answer

Have a look at this example, let me know if this is what you are looking for.

JavaScript

Giving 6 as input will output

JavaScript

You can use recursion so that it can be used up to any level. No need to limit the levels.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement