title: How to re-use my variables outside the if statements
body: <p>I'm trying to figure out how I can re-use my $php_file &amp; doc_file variables outside of my if statements?</p>
  <p>Here's the scenario...</p>
  <p>Generally for every file(.pdf/.doc/whatever) gets uploaded to the file path, there's also a php file that gets created as well. Here's a quick breakdown below.</p>
  <blockquote>
  <p>myuploaded_file.pdf</p>
  <p>myuploaded_file.pdf.php</p>
  </blockquote>
  <p>Basically I'm trying to distinguish these files into their own defined variables, so my end-results would be as followed...</p>
  <pre><code>$doc_file=myuploaded_file.pdf
  
  $php_file=myuploaded_file.pdf.php
  </code></pre>
  <p>And then basically run it in a loop for all of the uploaded files in that directory.</p>
  <p>I have it fairly close to where I need it to be i.e. the variables are defined properly when being utilized within each of the if statements, however I'm seeing how I can use these variables outside of the if statements, now that the files are properly defined into their own variables based on the file types.</p>
  <p>I can't even echo these variables outside of the if statements without running into &quot;doc_file or php_file variable is not defined&quot;. I tried tinkering with setting global variables, var_dump's, etc. but I'm still having no luck. Any ideas?</p>
  <p>UPDATED CODE</p>
  <pre><code>&lt;?php
  // Open the folder
  $f_path = &quot;files/News/&quot;; 
   
  $dir_handle = @opendir($f_path) or die(&quot;Unable to open $f_path&quot;); 
  
  // Loop through the files 
  while ($file = readdir($dir_handle)) { 
      $doc_file=&quot;&quot;;
      $php_file=&quot;&quot;;
  
      // Verify files
      if($file == &quot;.&quot; || $file == &quot;..&quot; ) {
          continue;
      }
      // Validate if the file is appended with .php
      if (strpos($file , '.php') !==false) {
          $php_file = $file;
          //echo &quot;PHP: $php_file &lt;br /&gt;&quot;;
      }
      // Print out the files that don't contain the .php extension
      else {
          $doc_file = $file;          
          //echo &quot;PDF: $doc_file &lt;br /&gt;&quot;;
      }
  echo &quot;PHP: $php_file &lt;br /&gt;&quot;;
  echo &quot;PDF: $doc_file &lt;br /&gt;&quot;;
  }
  
  
  // Close 
  closedir($dir_handle);
  
  ?&gt;
  </code></pre>
  <p>RESULTS FROM THE LOOP</p>
  <p>I'm seeing how I can avoid the blank values returning in my results?</p>
  <p>PHP:</p>
  <p>PDF: uploaded_file1.pdf</p>
  <p>PHP: uploaded_file1.pdf.php</p>
  <p>PDF:</p>
  <p>PHP:</p>
  <p>PDF: uploaded_file1.pdf</p>
  <p>PHP: uploaded_file1.pdf.php</p>
  <p>PDF:</p>