-4

In windows when we see detail view of folder and order by name i want exactly that sequence

in windows i get LEU2G0014L1A01.pdf as first in order but by my code i get LEU2G001041B01.pdf first in array any solution.?

<?php

$dir = "A/";
$result =   find_all_files($dir);


sort($result);
print_r($result);

function find_all_files($dir) 
{ 
$root = scandir($dir); 
  foreach($root as $value) 
  { 
      if($value === '.' || $value === '..') {continue;} 

        if(is_file("$dir/$value")) {$result[]="$value";continue;} 
          foreach(find_all_files("$dir/$value") as $value) 
          { 
             $result[]=$value; 

          } 

  } 

return $result; 
} 
?>
Apoorva Shah
  • 632
  • 1
  • 6
  • 15

2 Answers2

2

you're probably looking for natural sort http://php.net/manual/en/function.natsort.php

Eduard Gamonal
  • 8,023
  • 5
  • 41
  • 46
0

Consider the following example obtained from php manual site: http://www.php.net/manual/en/function.scandir.php

<?php
$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}

sort($files);
print_r($files);
rsort($files);
print_r($files);
?>

Produces the following output:

Array
(
    [0] => .
    [1] => ..
    [2] => bar.php
    [3] => foo.txt
    [4] => somedir
)
Array
(
    [0] => somedir
    [1] => foo.txt
    [2] => bar.php
    [3] => ..
    [4] => .
)
JTFRage
  • 387
  • 7
  • 20