title: how to sort folders first with scandir and using usort
body: <p>For a filemanagement, I use <code>create_function</code> to sort folders(directories) first and then files. But it seems that <code>create_function</code> is deprecated in php 7.2.</p>
  
  <p>So how can I use the <code>usort</code> below correctly?</p>
  
  <pre><code> $files = array_diff( scandir($dir), array(".", "..", "tmp") );
  
   usort ($files, create_function ('$a,$b', '
    return    is_dir ($a)
      ? (is_dir ($b) ? strnatcasecmp ($a, $b) : -1)
      : (is_dir ($b) ? 1 : (
          strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION)) == 0
          ? strnatcasecmp ($a, $b)
          : strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION))
      ))
    ;
  '));
  </code></pre>