PHP 5引入了DirectoryIterator,而PHP 5.3引入了FileSystemIterator.
FileSystemIterator扩展DirectoryIterator,但文档没有说明它带来了什么额外的功能.
你能告诉之间的区别DirectoryIterator和FileSystemIterator?
1]哪个功能更快?
2]有什么区别?
Differences
1] readdir返回目录中下一个条目的名称.Scandir从目录中返回一组文件和目录.
2] readdir必须打开资源句柄,直到读取所有条目.scandir,也许会创建一个包含所有条目的数组并关闭资源句柄?
可能重复:
glob() - 按日期排序
我想通过使用php glob基于上传日期对文件进行排序.如何通过在列表中显示最新的"已修改"/上传的图片来对其进行排序?
<?php
$files = glob("uploaded_files/*.*");
for ($i=0; $i<count($files); $i++) {
$num = $files[$i];
asort($files);
echo '<img src="'.$num.'" style="height:180px; width:180px; border:2px solid black; margin:20px 0px 10px 10px; *margin:10px 0px 10px 20px;" />'." ";
}
?>
Run Code Online (Sandbox Code Playgroud) 我在用
foreach(glob("config/pages/*.php") as $page){
Run Code Online (Sandbox Code Playgroud)
获取目录中所有文件的列表config/pages/我是否可以先显示最旧的文件,最新的文件最后显示?
我想要制作出所有这些的导航菜单.我的完整源代码如下,但我需要先显示最旧的文件,也许我可以为每个文件添加一个变量,如:`$ order = 1;' 数字是列表中的顺序?
所以例如对于页面home.php,$order它将等于0并且about.php将等于1.然后以某种方式排序基于从0开始的顺序计数?
<ul class="sidebar-nav">
<li class="sidebar-brand"><a href="#"><?php echo $config['site_title']; ?></a></li>
<?php
$files = glob("config/pages/*.php");
$files = array_combine(array_map("filemtime", $files), $files);
ksort($files);
foreach($files as $page){
// Remove the conifg/pages/ from the string
$strip1 = str_replace('config/pages/', '', $page);
// Remove the .php from the string
$strip2 = str_replace('.php', '', $strip1);
// Uppercase the first letter in the string
$capit = ucfirst($strip2);
// Re-define the string as …Run Code Online (Sandbox Code Playgroud)