note 47913 added to language.variables.scope

From: Date: Sun, 05 Dec 2004 10:02:43 +0000
Subject: note 47913 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-81386@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47913 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47913&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47913&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47913&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47913&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47913&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47913&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47913&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81386) next »