note 35378 added to language.variables.variable

From: Date: Fri, 29 Aug 2003 04:18:29 +0000
Subject: note 35378 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-55274@lists.php.net to get a copy of this message
Using variable variables with arrays, I've been searching quite a bit for it and have not found any solutions, and the comments here indicate the same as what i found, that $myarray = array ('Sierra Nevada','Sam Adams'); $arraypath = 'myarray[0]'; echo ${$arraypath}; does not work (at least not in PHP 4.3.2). A "dirty" workaround is to use eval, but be careful and do not use submitted data in the eval statement directly (Security).. Instead of the echo above you could do something like eval ('$myval = $'.$arraypath.';'); echo $myval; (Could also do echo in the eval, depending on what you need the value for) ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35378 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35378&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35378&report=yes

« previous php.notes (#55274) next »