PHP注意:数组_walk_递归函数中未定义变量
我有以下代码用于下载我的文件:PHP注意:数组_walk_递归函数中未定义变量,php,arrays,Php,Arrays,我有以下代码用于下载我的文件: $id = '251'; $type = 'download'; $post_type = 'news'; $file_name = 'C_3.docx'; $files = _files_list_($id,$type); print_r($files); array_walk_recursive($files, function ($value) { if (false !== stripos($value, $file_name)) { //
$id = '251';
$type = 'download';
$post_type = 'news';
$file_name = 'C_3.docx';
$files = _files_list_($id,$type);
print_r($files);
array_walk_recursive($files, function ($value) {
if (false !== stripos($value, $file_name)) { // LINE 17
$file = ABSPATH.'/uploads/files/'. _is_file_author($id,$type,$post_type).'/'.$value.'';
( new Downloader( $file ) )->download();
echo $file;
}
});
打印($files)
:
Array([0]=>Array([0]=>docs/manager.zip)[1]=>Array([0]=>docs/C_3.docx))
但在实际操作中,我看到了这个错误(不检测$id
,$type
,$file\u name
,$post\u type
):
注意:未定义变量:第17行C:\xampp\htdocs\cmd\modules\download.php中的文件名
如何修复此错误?@发表好的评论并@send complete comments:
我改变
array_walk_recursive($files, function ($value)
到
这现在起作用了。
$file\u name
超出了此处的范围。你需要使用它。所以做一些类似于。函数($value)使用($file\u name)
。正如@DeDee所说,它很可能是未定义的。但是在上面的上下文中,它只是超出了范围。安德鲁,请把它作为答案贴出来。哦,我很好。想象中的互联网点无论如何也不会让我觉得好笑。@Andrew:错误修复,但不会检测$id、$type、$file\u name、$post\u type inarray\u walk\u recursive
确保您使用所有变量,也确保它们包含某种值。还要注意的是,像$\u GET
,$\u post
等超全局变量。。。无需通过使用即可访问。所以,你可以直接使用它们
array_walk_recursive($files, function ($value) use ($file_name, $post_type, $type, $id),