Finding parent key in nested arrays 
Author Message
 Finding parent key in nested arrays

Let's say I have some nested arrays, like so:

Array
(
  'key1' => Array
            (
              'key3' => value
              'key4' => value
            ),
  'key2' => Array
            (
              'key5' => value
              'key6' => value
            )
)

Let's now say I pass a reference to the array which is the value of
'key2' to a function. The function then receives the following in its
input:

Array
(
  'key5' => value
  'key6' => value
)

Is there any way in which the function can find the key of the parent
array (other than by me actually storing it in the array it is passed)?

--
Pete
====
*** Remove -NO-SPAM- from address to reply by email



Sat, 15 Oct 2005 02:54:48 GMT  
 Finding parent key in nested arrays
Peter Gaunt:

Quote:
> Let's say I have some nested arrays, like so:

> Array
> (
>   'key1' => Array
>             (
>               'key3' => value
>               'key4' => value
>             ),
>   'key2' => Array
>             (
>               'key5' => value
>               'key6' => value
>             )
> )

> Let's now say I pass a reference to the array which is the value of
> 'key2' to a function. The function then receives the following in its
> input:

> Array
> (
>   'key5' => value
>   'key6' => value
> )

> Is there any way in which the function can find the key of the parent
> array (other than by me actually storing it in the array it is passed)?

No. You will have to pass the entire array by reference.

Andr N?ss



Sat, 15 Oct 2005 05:09:43 GMT  
 Finding parent key in nested arrays

Quote:

> Peter Gaunt:

[snip]

Quote:
> > Is there any way in which the function can find the key of the parent
> > array (other than by me actually storing it in the array it is passed)?

> No. You will have to pass the entire array by reference.

Feared as much. Very annoying :-(

--
Pete
====
*** Remove -NO-SPAM- from address to reply by email



Sat, 15 Oct 2005 07:10:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. That nested nested nested if statement...

2. Browse key to include fields from parent file.

3. How to retrieve current key used on the parent file, especially when using XPlore

4. for every element of array find bounds in another array

5. How to pass the result (array) of the spawnned processes to parent when it complets

6. Finding nested brackets in text file

7. using preg_match to find specific nested table

8. Finding nested expressions in regexs

9. Finding most nested list

10. Copying grand parent, parent, and child records

11. tk_getOpenFile ... -parent locks up parent window

12. APL2: compress with nested arrays?

 

 
Powered by phpBB® Forum Software