title: PHP: sort folder first and then files
body: <pre><code>$dir = '/master/files';
  $files = scandir($dir);
  foreach($files as $file){
     if(($file != '.') &amp;&amp; ($file != '..')){
        if(is_dir($dir.'/'.$file)){
           echo '&lt;li class="folder"&gt;'.$file.'&lt;/li&gt;';
        }else{
           echo '&lt;li class="file"&gt;'.$file.'&lt;/li&gt;';
        }
     }
  }
  </code></pre>
  
  <p>From the script above, I get result:</p>
  
  <pre><code>images (folder)
  index.html    
  javascript (folder)
  style.css
  </code></pre>
  
  <p>How to sort the folder first and then files?</p>