Here is my problem. I want to get grand parent or parent of my child. Please check below.
Root
A H
B C I
E F G J K
Funtion getParent(data){
// Code is here
return parent;
}
I tried but stuck in nested loop , I want to create in PHP or javascript that will give me only one parent like
getParent([E,F,G]) then return will be **A**
getParent([E]) then return will be **B**
getParent([A,G]) then return will be **Root**
getParent([F,G,H]) then return will be **Root**
getParent([I]) then return will be **H**
getParent([Root]) then return will be **Root**
getParent([F,G]) then return will be **C**
getParent([B,C,K]) then return will be **Root**
Please have look and resolve this problem.