note 50529 modified in language.variables.variable by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Jun 2009 16:55:49 +0000 |
| Subject: | note 50529 modified in language.variables.variable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157405@lists.php.net to get a copy of this message | ||
Multidimensional variable variables. If you want to run the below as one big program, you'll
have to undefine $foo in between assignments.
<?php
$foo = "this is foo.";
$ref = "foo";
print $$ref;
# prints "this is foo."
$foo[1]['a_z'] = "this is foo[1][a_z].";
$ref = "foo[1][a_z]";
print $$ref;
# Doesn't print anything!
$foo = "this is foo.";
$ref = "foo";
$erf = eval("return \$$ref;");
print $erf;
# prints "this is foo."
$foo[1]['a_z'] = "this is foo[1][a_z].";
$ref = "foo[1][a_z]";
$erf = eval("return \$$ref;");
print $erf;
# prints "this is foo[1][a_z]."
?>
--was--
<?php
# Multidimensional variable variables
$foo = "this is foo.";
$ref = "foo";
print $$ref;
# prints "this is foo."
$foo[1]['a_z'] = "this is foo[1][a_z].";
$ref = "foo[1][a_z]";
print $$ref;
# Doesn't print anything!
$foo = "this is foo.";
$ref = "foo";
$erf = eval("return \$$ref;");
print $erf;
# prints "this is foo."
$foo[1]['a_z'] = "this is foo[1][a_z].";
$ref = "foo[1][a_z]";
$erf = eval("return \$$ref;");
print $erf;
# prints "this is foo[1][a_z]."
?>
http://php.net/manual/en/language.variables.variable.php