php计算目录中的图像并显示/输出为数字数组

时间:2011-08-16 03:04:34

标签: php arrays image count

正如标题所说,我要做的是计算目录中的图像数量并将其输出为数字,例如,如果有4个图像,我希望结果为:

01 | 02 | 03 | 04

到目前为止,我有这个:

$count = glob('images/{*.jpg}', GLOB_BRACE);

foreach($count as $filecount) {

 echo '<li><a href="#" id="' . $filecount . '">' . $filecount . '</a></li>';

}

输出path / filename.jpg但是没有关于如何将其转换为数字数组的线索,或者即使我在正确的球场。

像往常一样,所有的帮助都会受到赞赏并提前感谢。

2 个答案:

答案 0 :(得分:1)

该数组以数字形式编入索引(0 length -1 ),使用它来获取数字:

foreach($count as $index => $filecount) {
    $number = $index+1;

答案 1 :(得分:0)

 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);
      //...
 }