Let’s suppose I have below nested/multi-dim array:
array(
'World'=>array(
'Asia'=>array(
'Japan'=>array(
'City'=>'Tokyo'
)
)
)
);
I want to be able to find out all the parents in the heriarchy of current city.
For example, for the City, the response should be an array of parents containing:
array(
'World'=>array(
'Asia'=>array(
'Japan'
)
)
);
So how do I find all the parents in the chain in a nested array?
Recursion is your friend here. You need to traverse the array recursively and get all the parents. Your problem is discussed here, take a look at this comment.