Re: [PHP] defining vars within functions as global
on 06/09/02 10:45 PM, Michael Sims ([EMAIL PROTECTED]) wrote: > How about this: > > function foo() > { > return array ( > "foo" => "aaa", > "bar" => "bbb" > ); > } > > extract(foo()); > > echo $foo; > echo $bar; > ?> Very cool !! -- thanks to everyone's replies. Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] defining vars within functions as global
On Fri, 06 Sep 2002 13:52:08 +1000, you wrote: >Hi, > >I'd like to be able to define multiple variables within a function, and have >it available outside the function from the point the function is called... How about this: "aaa", "bar" => "bbb" ); } extract(foo()); echo $foo; echo $bar; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] defining vars within functions as global
You can either use global keyword or put the variable into $GLOBALS[] array.. See: http://www.php.net/manual/en/language.variables.scope.php Gurhan On Thu, 2002-09-05 at 23:52, Justin French wrote: > Hi, > > I'd like to be able to define multiple variables within a function, and have > it available outside the function from the point the function is called... > eg: > > function foo() > { > $foo = "aaa"; > $bar = "bbb"; > } > > foo(); > > echo $foo; > echo $bar; > > ?> > > How to I specify that $foo and $bar (defined in the func) are to be set > globally (ie, outside the function)? > > I'm aware I could return as array of values, but I'm interested to see if > there's another option > > > Justin > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] defining vars within functions as global
Justin French wrote: > function foo() > { > $foo = "aaa"; > $bar = "bbb"; > } > > foo(); > > echo $foo; > echo $bar; > > ?> > > How to I specify that $foo and $bar (defined in the func) are to be set > globally (ie, outside the function)? Why not use an include instead of a function? Joe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] defining vars within functions as global
Hi, I'd like to be able to define multiple variables within a function, and have it available outside the function from the point the function is called... eg: How to I specify that $foo and $bar (defined in the func) are to be set globally (ie, outside the function)? I'm aware I could return as array of values, but I'm interested to see if there's another option Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php