I have this code for download my files :
$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;
}
});
print_r($files) :
Array ( [0] => Array ( [0] => docs/manager.zip ) [1] => Array ( [0] => docs/C_3.docx ) )
But in Action i see this error (not detect $id , $type, $file_name, $post_type):
Notice: Undefined variable: file_name in C:\xampp\htdocs\cmd\modules\download.php on line 17
how do fix this error?
$file_nameis out of scope here. You need touseit. So do something like this..function($value) use ($file_name). And as @DeDee said, it could very well be undefined. But in the context above, it's just out of scope.array_walk_recursive