title: How do I fix "Undefined variable" error in PHP?
body: <p>Today, I have started to learn PHP. And, I have created my first PHP file to test different variables. You can see my file as follows.</p>
  <pre><code>&lt;?php
      $x = 5; // Global scope
  
      function myTest()
      {
          $y = 10; // Local scope
          echo &quot;&lt;p&gt;Test variables inside the function:&lt;p&gt;&quot;;
          echo &quot;Variable x is: $x&quot;;
          echo &quot;&lt;br&gt;&quot;;
          echo &quot;Variable y is: $y&quot;;
      }
  
      myTest();
  
      echo &quot;&lt;p&gt;Test variables outside the function:&lt;p&gt;&quot;;
      echo &quot;Variable x is: $x&quot;;
      echo &quot;&lt;br&gt;&quot;;
      echo &quot;Variable y is: $y&quot;;
  ?&gt;
  </code></pre>
  <p>I have found the following errors when I have run this file in the browser.</p>
  <blockquote>
  <p>Notice: Undefined variable: x in /opt/lampp/htdocs/anand/php/index.php on line 19</p>
  <p>Notice: Undefined variable: y in /opt/lampp/htdocs/anand/php/index.php on line 29</p>
  </blockquote>
  <p>How can I fix the issue regarding it?</p>