Re: q: extract() and get_defined_vars()

From: Date: Sat, 28 Jun 2003 00:48:09 +0000
Subject: Re: q: extract() and get_defined_vars()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-153235@lists.php.net to get a copy of this message
Hello, This is a reply to an e-mail that you wrote on Sat, 28 Jun 2003 at 01:41, lines prefixed by '>' were originally written by you. > If I call extract() inside of a function, then the variables it > creates will > be local to that function, correct? OK, so, is there a way to get > extract() > to define those variables as global, from within a function? Yes it is, you must tell the function to treat the relevant variables as globals though, here is a way of doing it: function Foo(){ $theArray = array('var1'=>'testing', 'var2'=>'testing2'); foreach($theArray as $varname=>$value){ global $$varname; } extract($theArray); } Foo(); echo "$var1<BR />$var2"; The above code outputs "testing<BR />testing2". All the best, David. -- phpmachine :: The quick and easy to use service providing you with professionally developed PHP scripts :: http://www.phpmachine.com/ Professional Web Development by David Nicholson http://www.djnicholson.com/ QuizSender.com - How well do your friends actually know you? http://www.quizsender.com/ (developed entirely in PHP)

« previous php.general (#153235) next »