What are the best practices for reading files from directories and storing them in an array in PHP?

When reading files from directories and storing them in an array in PHP, it's important to use the `scandir()` function to get a list of files in the directory, filter out any unwanted files (such as `.` and `..`), and then loop through the remaining files to read their contents and store them in an array.

$directory = '/path/to/directory';
$files = array_diff(scandir($directory), array('..', '.'));

$fileContents = [];

foreach ($files as $file) {
    $filePath = $directory . '/' . $file;
    $fileContents[$file] = file_get_contents($filePath);
}

print_r($fileContents);