Variable variables
| From: | Mark Steudel | Date: | Wed, 25 Jan 2006 00:49:48 +0000 |
| Subject: | Variable variables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-229196@lists.php.net to get a copy of this message | ||
I was wondering if you could create variable variables for objects, please
see examples below, Im having problems getting it to work.
$data['fieldname'] = foo;
// without variable variables
$res =& $db->query( "SELECT foo FROM table" );
while( $res->fetchInto( $db_data ) )
{
echo $db_data->foo; // pretend this echos bar
}
// with variable variables
$varVar = '$db_data->'.$data['fieldname']; // should be $db_data->foo
$res =& $db->query( "SELECT foo FROM table" );
while( $res->fetchInto( $db_data ) )
{
echo ${$varVar}; // would like this to echo bar
}
Thanks, Mark