PHP Classes

variable scope in fcns

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  variable scope in fcns  
Subject:variable scope in fcns
Summary:How to access variables next level up in function calls
Messages:6
Author:Brian Read
Date:2008-10-24 15:53:44
Update:2008-11-04 04:20:43
 

  1. variable scope in fcns   Reply   Report abuse  
Picture of Brian Read Brian Read - 2008-10-24 15:53:44
I have this:

a = 23;
function level1()
{$a = 29;level2();echo "<p>".$a."</p>";
}
function level2()
{global $a;echo "<p>".$a."</p>";
}
level1();
echo("Hello, World!" );
?>

The "global" makes $a take on the value of 23, whereas i really need to get it to take on the value of 29.

Clearly this is a simple example of a problem i have which is more complex!

There are 5 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.