PHP删除(.extension)文件,在目录和所有子目录的特定时间后修改

I need a little bit of help. I need to write a script that will look through all directories and sub-directories and delete specific extensions that are modified after specific time. I can get it to delete files from specific path, but I need the script to search inside sub directories. Is there any way to do that? I have tried this for files but I have no idea on how to make it work with directories and sub directories

$path = '/path/to/file/';
if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) { 
        $filelastmodified = filemtime($path . $file);
        if( $filelastmodified > "MY TIME STAMP" )
        {
           unlink($path . $file);
        }
        echo "deleted";
    }
    closedir($handle); 
}

Create a recursive function, if it finds a folder it calls itself passing the folder name.