Re: Variable Variables and Mulitdimensional Arrays

From: Date: Sat, 16 Mar 2002 17:53:14 +0000
Subject: Re: Variable Variables and Mulitdimensional Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-88759@lists.php.net to get a copy of this message
You seem to have three different ideas/questions... let me attempt to answer them: > Hi. I want to be able to access a key in a multidimensional array at some > depth "n" without knowing before runtime what the keys are. let's take a multidimensional array $x $x = array( "somevar", array( "otherval", "evenmore" ) ); echo $x[0]; should print 'somevar' echo $x[1]; should print 'Array' echo $x[1][0]; should print 'otherval' echo $x[1][1]; should print 'evenmore' > > I thought this might be possible using variable variables. Here's some > sample code using variable variables and multidimensional arrays: > $y = 'a'; > $z = 'b'; > $t = 'c'; > $x = array("a"=>array("b"=>array("c"=>TRUE))); > > // I want to be able to concatenate the array indexes into one variable > variable. This would be done in a loop at runtime. if you want to concat all the key's of an array with a loop you could do: reset($x); //just to make sure we are at the first key while(list($key,$val) = each($x)){ $my_keys .= $key } echo $my_keys; should result in: (using $x from my code above) 1 (I think it might even come out as 01 -- but probally 1 since it will be treated as a int maybe =) ) > > Any help would greatly be appreciated, > > Charlie > > Hope that helps, still not sure what your question was or if i answered it ;) -Joe

« previous php.general (#88759) next »