Notice: Undefined variable: var1 in \www\test.php on line 7
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2619573/how-to-use-include-within-a-function">How to use include within a function?</a>  </p>
</blockquote>



<p>i have two file </p>

<p><strong>inc.php file</strong></p>

<pre><code>&lt;?php
$var1 = "foo";
$var1 .= "bar";
?&gt;
</code></pre>

<p><strong>test.php File</strong></p>

<pre><code>&lt;?php
function getcontent($file) {
 include ($file);
}

getcontent('inc.php');
echo $var1;
?&gt;
</code></pre>

<p>When i run test.php it give me error in output</p>

<pre><code>Notice: Undefined variable: var1 in \www\test.php on line 7 
</code></pre>

<p>But when i change my test.php file to this</p>

<pre><code>&lt;?php
include ('inc.php');
echo $var1;
?&gt;
</code></pre>

<p>its works, and give me output fine</p>

<pre><code>foobar
</code></pre>
