note 60543 deleted from function.include by aidan

From: Date: Sat, 15 Apr 2006 16:28:48 +0000
Subject: note 60543 deleted from function.include by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108147@lists.php.net to get a copy of this message
Note Submitter: ---- When you include a page in a function, this page will have local scope, so you will need the 'global' keyword to use a variable from the global scope or to set a variable that the can be used in the global scope. Example: <?php //file.php (include file) //Using a var from the global scope global $a; echo $a; //Setting a var at the local scope include so that it can be used at the global scope global $b; $b = 'include var'; ?> <?php //main page $a = 'global var'; function doSomething() { //some code include('file.php'); } doSomething(); //Using a var from the local scope include echo $b; ?>

« previous php.notes (#108147) next »