Re: How to use a variable variable with an array

From: Date: Wed, 14 Dec 2011 06:11:52 +0000
Subject: Re: How to use a variable variable with an array
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-316004@lists.php.net to get a copy of this message
On Wed, Dec 14, 2011 at 9:27 AM, Nils Leideck <nils.leideck@leidex.net> wrote: > Hi Al, > > many thanks for your feedback. Unfortunately I don’t know the deepness of the array so I > can’t use the nested foreach() idea :-( Let me try to simplify my question (which also helps > myself to clarify my process ;-) > > I have a variable where the value is a string that is exactly the path to the array value: > > [code] >    $arrayPath = > "['user_interface’][‘design']['my_colors']['item_number_one’]”; > [/code] > > And I have an array that has all the details: > > [code] >    $myArray = coolFunction(‘getArray’); > [/code] > > The question is, how can I use these both informations to return a value from the $myArray? > > Examples I tried unsuccessfully: > > [code] >    [...] >    echo $myArray$arrayPath; >    echo $myArray{$arrayPath}; >    echo $myArray${arrayPath}; >    echo $myArray${$arrayPath}; >    echo $myArray.$arrayPath; >    echo $myArray.$arrayPath; >    [...] > [/code] >    etc... > > your feedback is much much much appreciated!!! > > Cheers, Nils > -- > http://webint.cryptonode.de / a Fractal project for you quesion, try eval: <?php $arr = array("a"=>array("b"=>array("c"))); $key = "['a']'['b]"; $value = eval("return \$arr". $key .";"); ?> ps: your requirement is a little odd :) thanks > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- Laruence  Xinchen Hui http://www.laruence.com/

« previous php.general (#316004) next »