What is the best practice for reading multiple files from a directory in PHP without specifying the number of files?

When reading multiple files from a directory in PHP without specifying the number of files, it is best to use a loop to iterate through the files in the directory. This way, you can dynamically read all files without knowing the exact number beforehand.

$directory = "/path/to/directory/";
$files = scandir($directory);

foreach($files as $file){
    if(is_file($directory . $file)){
        // Process the file content here
        $content = file_get_contents($directory . $file);
        echo $content;
    }
}