I have an array that can vary in its dimension, sometimes can be small, sometimes can go deeper. I'm trying to search for a particular element in the array and if it is found, I would like to get a specific parent. So for instance, if I have an array as:
Again, the dimension can change, however, I'm looking for the the most outer parent's key that has siblings. (in this case)
Array (
[0] => Array (
[0] => Array (
[0] => Array ( <<----------------------------------------+
[0] => FOO0 |
[1] => BAR0 //Search BAR0 returns parent key 0 +
[2] => Array( |
[0] => HELLO0 |
[1] => BYE0 //Search BYE0 returns parent key 0 +
) |
[3] => FOO0 |
[4] => Array ( |
[0] => HELLO0 //Search HELLO0 returns parent key 0 --
)
)
[1] => Array ( <<----------------------------------------+
[0] => FOO1 |
[1] => BAR1 |
[2] => Array ( |
[0] => HELLO1 |
[1] => BYE1 |
) |
[3] => BASE1 |
[4] => Array ( |
[0] => BAZ1 |
[1] => Array ( |
[0] => DOO1 //Search DOO1 returns parent key 1 +
[1] => BOB2 //Search BOB2 returns parent key 1 +
)
)
)
[2] => FOO2 // Search FOO2 returns key 2 (itself)
)
)
)
Sample Output for FOO2
[2] => FOO2 // searched value
I would really appreciate some help! Thanks!