Page 1 of 1

variables and function within a function

Posted: Tue Jun 22, 2004 6:10 am
by bkk_mike
I have a piece of code like this:
function a()
{
$a="some value"
$b="some other value"
function b($someArg)
{.....}
function c($someArg)
}
in function b and c, I would like to access the values of $a and $b.
how can I do that?
Thanks a bunch in advance :-)

Posted: Tue Jun 22, 2004 7:47 am
by Grim...

Code: Select all

<?php
global $a, $b;
?>

Posted: Tue Jun 22, 2004 8:03 am
by patrikG
or

Code: Select all

function a(){
   ...
   ...
   return array($a,$b);
}

function b(){
  list(a,b)=a();
}

Posted: Tue Jun 22, 2004 9:45 am
by pickle
Return values from functions rather than declaring globals. If you get into the habit of declaring globals, it's harder to trace back where a variable gets it's value set.