note 38042 added to language.types.array

From: Date: Fri, 05 Dec 2003 19:29:27 +0000
Subject: note 38042 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-61461@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38042 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38042&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38042&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61461) next »