Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php递归列出*.json文件_Php_Arrays - Fatal编程技术网

使用php递归列出*.json文件

使用php递归列出*.json文件,php,arrays,Php,Arrays,我使用php递归列出文件夹中的所有文件: <?php $it = new RecursiveDirectoryIterator("."); foreach(new RecursiveIteratorIterator($it) as $file) { echo $file . "<br/> \n"; } 您可以使用->getExtension()方法在foreach中签出: $it = new RecursiveDirectoryIterator("."); fore

我使用php递归列出文件夹中的所有文件:

<?php

$it = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($it) as $file)
{
    echo $file . "<br/> \n";
}

您可以使用
->getExtension()
方法在foreach中签出:

$it = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($it) as $file) {
    if($file->getExtension() == 'json') { // add a condition here
        echo $file . "<br/> \n";
    }  
}
$it=new RecursiveDirectoryIterator(“.”);
foreach(新的递归迭代器($it)作为$file){
如果($file->getExtension()='json'){//在此处添加一个条件
echo$文件。“
\n”; } }
因为多样性:

$rdi = new RecursiveDirectoryIterator('.');
$rii = new RecursiveIteratorIterator($rdi);
$ri = new RegexIterator($rii, '/^.+\.zzz$/i', RecursiveRegexIterator::GET_MATCH);

foreach ($ri as $file) { ... }
$ri将为每个.zzz文件包含一个索引数组

  • 根据文档注释中的示例修改:
,或者如果你想继续主题。