php - Get function variables on included file -
i have function this:
function form($filename){ $text=""; if (file_exists(dirname(__file__)."/other/".$filename)){ ob_start(); include "other/".$filename; $text = ob_get_clean(); } homecoming $text; }
and, somewhere in code, have that:
class first { public function execute() $an_array=array("hi","goodbye"); homecoming form("my_form.php"); }
now know how values of $an_array
on "my_form.php". function form
used other files need more 1 variable.
edit
i want included file read more 1 parameter. in other words, on other class, have this:
class sec { public function execute() $first_array=array("hi","goodbye"); $second_array=array("other","another"); homecoming form("another_form.php"); }
in case, read both $first_array
, $second_array
on another_form.php
file.
edit 2
is there way create form
function work php's array_push
function? in other words, want have sec parameter on form
acts lastly parameter of array_push
.
function form($filename, $special = array()){ $text=""; $file = $filename; if (file_exists(dirname(__file__)."/other/".$filename)){ ob_start(); include $file; $text = ob_get_clean(); } homecoming $text; } class re-create { public function execute() { $array = array(); $array['first_array'] = array( "first", "second" ); $array['second_array'] = array( "third", "fourth" ); homecoming form("my_form.php", $array); } } $copy = new copy(); echo $copy->execute();
this way can pass more 1 parameter. $special
available in my_form.php , this:
array ( [first_array] => array ( [0] => first [1] => sec ) [second_array] => array ( [0] => 3rd [1] => 4th ) )
update:
you way, if don't want alter variable names
function form($filename, $special = array()){ $text = ''; if (file_exists(dirname(__file__)."/other/".$filename)){ extract($special); ob_start(); include $file; $text = ob_get_clean(); } homecoming $text; } class re-create { public function execute() { homecoming form("my_form.php", array( 'var1' => 'test', 'var2' => 'test2' )); } } $copy = new copy(); echo $copy->execute();
in my_form.php
variables available
echo $var1; // test echo $var2; // test2
php function variables parameters include
No comments:
Post a Comment