ディレクトリ配下のファイル名が id と 日付で、拡張子が .json のみ取得するphp php

ディレクトリ配下のファイル名が id と 日付で、拡張子が .json のみ取得するphp

// ディレクトリ配下のファイル拡張子が .json のみ取得
$ext = .json ;
$condition = ;

if( $id != ) { $condition = $id . _ ; }
if( $date != ) {$condition .= $date . _ ; }

$files = array();
while($file = readdir($dir)) {
if(is_file(LOG_DIR.$file) && preg_match( /$condition(.*)$ext$/ LOG_DIR.$file)) {
$files[] = $file;
}
}