正如标题所说,我要做的是计算目录中的图像数量并将其作为数字输出例如,如果有4张图像,我希望结果为:
01 | 02 | 03 | 04
我到目前为止有这个:
$count = glob('images/{*.jpg}', GLOB_BRACE);
foreach($count as $filecount) {
echo '<li><a href="#" id="' . $filecount . '">' . $filecount . '</a></li>';
}
输出路径/filename.jpg,但没有线索如何将其转换为数字数组,甚至如果我在正确的球场。
像往常一样,感谢所有的帮助,并提前感谢。
该数组是数字索引(0
到长度-1
),使用它来获得数字:
foreach($count as $index => $filecount) {
$number = $index+1;
foreach($count as $index => $filecount) {
// $number is "01" for the first and "02" for second etc
$number = str_pad($index, 2, "0", STR_PAD_LEFT);
//...
}