note 47913 deleted from language.variables.scope by sean
| From: | sean@php.net | Date: | Sun, 05 Dec 2004 14:37:18 +0000 |
| Subject: | note 47913 deleted from language.variables.scope by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-81395@lists.php.net to get a copy of this message | ||
Note Submitter: adam.pippin at accesscomm dot ca
----
How to truly import global variables into a function (EG: the global variable $a will be accessible
with $a, $b with $b, etc.)
<?php
function myfunction()
{
foreach ($GLOBALS as $key=>$value)
{
$$key = $value;
}
}
?>
As an example:
<?php
function displayformula()
{
foreach ($GLOBALS as $key=>$value)
{
$$key = $value;
}
echo "$a + $b = $c\n";
}
$a = 5;
$b = 2;
$c = $a + $b;
displayformula();
?>
Outputs:
5 + 2 = 7
----
Reason: useless example