PHP - Find parent key of array
Posted
by Jordan Rynard
on Stack Overflow
See other posts from Stack Overflow
or by Jordan Rynard
Published on 2010-03-24T00:55:40Z
Indexed on
2010/03/24
1:03 UTC
Read the original article
Hit count: 455
I'm trying to find a way to return the value of an array's parent key.
For example, from the array below I'd like to find out the parent's key where $array['id'] == "0002". The parent key is obvious because it's defined here (it would be 'products'), but normally it'd be dynamic, hence the problem. The 'id' and value of 'id' is known though.
[0] => Array
(
[data] =>
[id] => 0000
[name] => Swirl
[categories] => Array
(
[0] => Array
(
[id] => 0001
[name] => Whirl
[products] => Array
(
[0] => Array
(
[id] => 0002
[filename] => 1.jpg
)
[1] => Array
(
[id] => 0003
[filename] => 2.jpg
)
)
)
)
)
© Stack Overflow or respective owner