I have a one core php file in which i want to get file name in a particular folder with order like,
I have many files but each file name like filename_0,filename_1,filename_2 like this so when ever i fetch file name in folder that is not proper order and i am getting filename_0,filename_2,filename_1..
$dir_path="/var/lib/myproject";
$folder=dir("$dir_path");
$j=0;$allfilename='';
while($folderEntry=$folder->read())
{
if($folderEntry == '.' || $folderEntry == '..' )
{
continue;
}else{
echo "Path of directory is>>>>>>>>".$folderEntry;
$allfilename[]=$folderEntry;
$j++;
}
}
$folder->close();
i can fetch file name but not getting order so any order loke incremented filename_0 to continue file name …..
so can any one any idea how to get file name with ascending order.
You can always natsort the filename array.
Note here natural sort is necessary as you might want to consider
filename_1is beforefilename_100. Another option is using sort function.