douyan8961 2015-01-12 17:28
浏览 41

为什么array_filter函数只能用于PHP循环中的最后一个目录?

While looping through various directories, I used array_filter to put the directories' filenames into an array, then we proceed to the next directory;

The value of $HALLO1 is a value that is read from an array.

One thing I noticed is that when array_filter() is operated on $HALLO1 and in the case where $HALLO1 is equal to an array of directories, the var_dump() function does not list files in the first directories but only list the files contained in last directory. However, when $HALLO1 is equal to one and only directory the array_filter() works and lists all the files contained in that directory. Why is that ?

<?php

foreach ($CC1 as $directory)  {
    $GG1 = strval($CC1[$dd]);
    $HALLO1 = $GG1;
    echo "HALLO1 = " . $HALLO1 ;
    $iterator = new DirectoryIterator(dirname($HALLO1));
    //*****************************************************
    $f_files = array_filter(glob("$HALLO1*"), 'is_file');
    var_dump($f_files);
    //*****************************************************
    ++$dd; 
    } 

?>
  • 写回答

1条回答 默认 最新

  • duanqiongdu9916 2015-01-12 17:40
    关注

    Because you're overwriting $f_files in each iteration

    $f_files = array()
    foreach ($CC1 as $directory)  {
        $GG1 = strval($CC1[$dd]);
        $HALLO1 = $GG1;
        $f_files = array_merge($f_files, array_filter(glob("$HALLO1*"), 'is_file'));
    }
    var_dump($f_files);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line