Referencing Multi Dimensional Arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
	I've kind of solved this question already using recursion but I
recon (in the grand tradition) that someone has a better solution!

I have an multi dimensional array that is of variable depth, a snippet
is shown below. The problem is that I don't know how deep the array goes
as any entry can contain further entries which can contain further
entries and as the array grows the data is increasingly unknown. My
first thought was to use variable variables but the following doesn't
work:

$Network = array(--as-below--);

$MyKey = "[allocations][network][0]";
print $Network[$$MyKey];

Now the obvious use of

print $Network[$$key1][$$key2];

won't work for me as sometimes I need to be two layers deep and other
times five.

As I mentioned I've solved this problem using recursive functions but
it's all a bit nasty. I've knicked various functions from the php site
to search multi-dimensional arrays and can return myself an array of
keys leading to the item I'm after but I can't seem to use that array to
reference the data!

All/any solutions or pointers (no pun intended) welcome.

Kind regards

Matthew

Array
(
    [allocations] => Array
        (
            [network] => Array
                (
                    [0] => Array
                        (
                            [address] => 10.0.0.0
                            [netbits] => 8
                            [name] => TEST
                            [creationdate] => 20041124
                            [description] => Test Address Space
                            [security] => Array
                                (
                                    [alloc] => intech
                                    [subnet] => intech
                                    [unalloc] => intech
                                )

                            [free] => Array
                                (
                                    [0] => Array
                                        (
                                            [netbits] => 9
                                            [address] => 10.128.0.0
                                            [creationdate] => 20041125
                                        )

                                    [1] => Array
                                        (
                                            [netbits] => 10
                                            [address] => 10.64.0.0
                                            [creationdate] => 20041125
                                        )
                               )

                            [network] => Array
                                (
                                    [0] => Array
                                        (
                                            [address] => 10.0.0.0
                                            [netbits] => 24
                                            [name] => MAFFNET
                                            [creationdate] => 20041125
                                            [security] => Array
                                                (
                                                    [alloc] => intech
                                                    [subnet] => intech
                                                    [unalloc] => intech
                                                )

                                            [description] => A Test
network
                                            [free] => Array
                                                (
                                                    [address] =>
10.0.0.0
                                                    [netbits] => 24
                                                    [creationdate] =>
20041125
                                                )
							)
					)
			)
	)
)

________________________________________________________________________
This message has been checked for all known viruses by the 
CitC Virus Scanning Service powered by SkyLabs. For further information visit
http://www.citc.it

___

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux