Glob目录/文件夹列表的结果数限制 [英] Limit number of results for glob directory/folder listing

查看:200
本文介绍了Glob目录/文件夹列表的结果数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在以下代码中将目录结果/pdf的数量限制为8个?

How would I go about limiting the number of directory results/pdfs to, say 8, in the following code?

$counter = 0; 
foreach (glob("/directory/*.pdf") as $path) { //configure path
    $docs[filectime($path)] = $path;
} 
krsort($docs); // sort by key (timestamp)               
foreach ($docs as $timestamp => $path) {
    echo '<li><a href="/directory/'.basename($path).'" class="'.($counter%2?"light-grey":"").'" target="_blank">'.basename($path).'</a></li>';
    $counter++;                     
}

这可能真的很容易,但是我似乎无法弄清楚-谢谢你,S.

This is probably really easy but I can't seem to be able figure it out - thanks in advance, S.

推荐答案

foreach (array_slice(glob("/directory/*.pdf"),0,8) as $path) {

这篇关于Glob目录/文件夹列表的结果数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆