arrays - How to sort a list of files & directories so directories are listed first in PHP -


How can I sort a list of files & amp; Directory directories are listed in PHP first ??? I try natsort, but it's just alphabetical order like my source:

  $ dirFiles = array (); $ Path = "./folder_path"; // Opens the images folder if ($ handle = opendir ($ path)) while {wrong! == ($ file = readdir ($ handle))} {if ($ file! = "." & Amp; $ file ! = ".." & $ file! = "Index.php" & amp; $ file! = "thumbnail" & amp; $ file! = ".DS_Store") {$ isdir = $ path $ file; If (is_dir ($ isdir)) {$ dirFiles [] = $ file; } If (! Is_dir ($ isdir)) {$ dirFiles [] = $ file; }}} Closed ($ handle); } Natsort ($ dirFiles);   

Listing files and directories

  foreach ($ dirFiles $ file = & gt; $ value) {$ name = basename ($ value); $ Name echo; } You can create a multi-dimensional array:  
    

if_dir ($ isdir)) {$ dirFiles ['dir'] [] = $ file; } If ($! Isdir) {$ dirFiles ['file'] [] = $ file; }

To list files and directories:

  ksort ($ dirFiles); Foreign currency ($ dirFiles as dollar files) {foreach (files $ $ as file) {$ name = basename ($ file); $ Name echo; }}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -