title: PHP - Deleting folder/files only if there are no more in there
body: <p><code>$value</code> can = a folder structure to the language file.  Example:  languages/english.php</p>
  
  <p><code>$value</code> can also = the files name.  Example:  english.php</p>
  
  <p>So I need to get the current folder that <code>$value</code> is in and delete the folder ONLY if there are no other files/folders within that directory (after deleting the actual file as I am doing already, ofcourse).</p>
  
  <pre><code>foreach($module['languages'] as $lang =&gt; $langFile)
  {
          foreach ($langFile as $type =&gt; $value)
          {
              @unlink($module_path . '/' . $value);
              // Now I need to delete the folder ONLY if there are no other directories inside the folder where it is currently at.
              // And ONLY if there are NO OTHER files within that folder also.
          }
  }
  </code></pre>
  
  <p>How can I do this??  And wondering if this can be done without using a while loop, since a <code>while</code> loop within a <code>foreach</code> loop could take some time, and need this to be as quick as possible.</p>
  
  <p>And just FYI, the $module_path should never be deleted.  So if <code>$value = english.php</code>, it should never delete the $module_path.  Ofcourse, there will always be another file in there, so checking for this is not necessary, but won't hurt either way.</p>
  
  <p>Thanks guys :)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok, now I'm using this code here and it is NOT working, it is not removing the folders or the files, and I don't get any errors either... so not sure what the problem is here:</p>
  
  <pre><code>foreach($module['languages'] as $lang =&gt; $langFile)
  {
      foreach ($langFile as $type =&gt; $value)
      {
          if (@unlink($module_path . '/' . $value))
              @rmdir(dirname($module_path . '/' . $value));
      }
  }
  </code></pre>
  
  <p>NEVERMIND, this works a CHARM!!!  Cheers Everyone!!</p>