note 80482 deleted from language.references.arent by tularis
| From: | tularis@php.net | Date: | Mon, 21 Jan 2008 11:38:55 +0000 |
| Subject: | note 80482 deleted from language.references.arent by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135284@lists.php.net to get a copy of this message | ||
Note Submitter: frank
----
If you have an array like... $a=array('x'=>1,'y'=>2);
you might want have all variables referenced to the array elements.
It works! My function:
function my_make_vars(&$a)
{ foreach ($a as $n=>$v)
{ global $$n;
$$n=$v;
$a[$n] =& $$n;
}
}
$a=array('x'=>1,'y'=>2);
my_make_vars($a);
# Now $x and $a['x'] are the same variable ;-)
print $x.$y.' ';
$a['x']=3;
print $x.' '; # -> 3
$x=4;
print $a['x'].' '; # -> 4