php - pass a variable to an include through function -


i want pass variable including file through function. example have 2 files: index.php:

<?php $var = "this variable"; function get_template($template){     require_once "theme/".$template; } get_template("index.php"); ?> 

than have file: theme/index.php:

<?php echo $var; ?> 

how can make $var global through function without writing global $var inside function?

pass in parameter function. manual:

when file included, code contains inherits variable scope of line on include occurs. variables available @ line in calling file available within called file, point forward. however, functions , classes defined in included file have global scope.

$var = "this variable"; function get_template($template, $var){     require_once "theme/".$template; } get_template("index.php", $var); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -