Searching for a key in a multi dimensional array and adding it to another array [migrated]
- by Moha
Let's say I have two multi dimensional arrays:
array1 (
stuff1 = array (
data = 'abc'
)
stuff2 = array (
something = '123'
data = 'def'
)
stuff3 = array (
stuff4 = array (
data = 'ghi'
)
)
)
array2 (
stuff1 = array (
)
stuff3 = array (
anything = '456'
)
)
What I want is to search the key 'data' in array1 and then insert the key and value to array2 regardless of the depth. So wherever key 'data' exists in array1 it gets added to array2 with the exact depth (and key names) as in array1 AND without modifying any other keys.
How can I do this recursively?