What are the potential pitfalls of using a for loop to read files from a directory in PHP?

Using a for loop to read files from a directory in PHP can be inefficient and error-prone, as it requires manual handling of file paths and potential issues with file permissions. A better approach is to use the built-in functions like `scandir()` or `glob()` which can easily retrieve the list of files in a directory without the need for manual iteration.

// Using scandir() to read files from a directory
$directory = "/path/to/directory";
$files = scandir($directory);

foreach($files as $file) {
    if($file != '.' && $file != '..') {
        // Process each file here
        echo $file . "\n";
    }
}