title: PHP using extract() to pass array values as variables and display it on a page
body: <p>I am attempting to create a <code>view($path,$data)</code> function in <code>php</code> the main functionality is include a specific file from the directory and pass in data/variable into that page, i managed to create <code>$path</code> and was able to include the define path, now my next step is pass in the <code>$data</code> values into my included page, and want to convert each array label as a variable.</p>
  
  <p>My php class is below <code>classes.php</code>.</p>
  
  <pre><code>define("SITE_NAME", "process");
  
   class helpers {
  
  
          public function view($path, $data) 
          {
  
              $dir = $_SERVER['DOCUMENT_ROOT'].SITE_NAME."/";
  
              include($dir.$path.".php");
  
              return extract($data);
  
  
  
          }  
  
  }
  </code></pre>
  
  <p>On my index.php</p>
  
  <pre><code>require_once('classes.php');
  
  $helper = new Helpers();
  
  $data['title'] = "My Test";
  $data['test'] = "test1";
  
  $helper-&gt;view('test',$data);
  </code></pre>
  
  <p>So now on my test.php i am tring to echo <code>$title</code> which i assuming it will return the value of <code>My Test</code>, to test if i am getting the values from <code>index.php</code> i was able to output the <code>$data</code> using <code>print_r</code></p>
  
  <p><code>Array ( [title] =&gt; My Test [test] =&gt; test1 )</code></p>
  
  <p>Any advice how can i achieve? i was trying the <code>extract()</code> function but don't know if my syntax is correct.Thanks in advance!</p>