I am trying to pass an array as an argument to the new php file.
$data=array('arr1'=>'haha', 'arr2'=>'wawa');
function load($view='index',$data=false){
require $view.'.php';
if (isset($data)){
//I want to pass $data(array) to index.php so I can use the array
//in index.php page.
//not sure what to do here.
}
}
load('index', $data);
index.php
<html>
echo '$arr1 ='.$arr1;
echo '$arr2 ='.$arr2;
</html>
Is this possible? Thanks for any helps.
You can already access that array.
in your index.php you can do:
Because you are in the scope of your function.
Please note that are many template engine out there, I strongly suggest you to use one of them.