function getfiles($path)

foreach(scandir($path) as $afile)
{
if($afile=='.'|| $afile=='..') continue; 
if(is_dir($path.'/'.$afile)) 

getfiles($path.'/'.$afile); 
} else { 
echo $path.'/'.$afile.'</br>';



getfiles('\images');如何上,如何把echo的值以数组形式在函数中返回?谢谢

解决方案 »

  1.   

    function getfiles($path)
    {
      $res = array();
      foreach(scandir($path) as $afile)
      {
        if($afile=='.'|| $afile=='..') continue; 
        if(is_dir($path.'/'.$afile)) 
        { 
          $res = array_merge($res, getfiles($path.'/'.$afile)); 
        } else { 
          $res[] = $path.'/'.$afile;
        }
      } 
      return $res;
    } $d = getfiles('images');
      

  2.   

    写了个类,可直接使用
    http://blog.csdn.net/fdipzone/article/details/8704191
      

  3.   

    你的递归没有写错,只是你写的不是已数组返回而已。而是直接echo输出。
    echo $path.'/'.$afile.'</br>';
    改为
    $ret[] = $path.'/'.$afile; 
    就可保存到数组了