note 38724 deleted from language.types.array by sp

From: Date: Sun, 04 Jan 2004 23:53:34 +0000
Subject: note 38724 deleted from language.types.array by sp
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62916@lists.php.net to get a copy of this message
Note Submitter: Otter ---- Kieran wrote: I ran across something that should be noted... Take care when using variables for referencing arrays. PHP will interpret the square bracket syntax [] as a substr() like reference.... <? // this doesn't work, PHP evaluates $($foo[$bar]) instead of ($$foo)[$bar] $temp = $$foo[$bar]; /*--------------------------------------------------------*/ // use this method instead: // make a temp array so we can refer to it by an absolute name $temp_array = $$foo; // now pull the value $temp = $temp_array[$bar]; ?> Cheers! Kieran You may also do this: <? $temp = ($$foo)[$bar]; //Or... $temp = $($foo[$bar]); ?> I forget where I read this... somewhere in documentation

« previous php.notes (#62916) next »