How can you automatically populate an array in PHP based on files in a directory?
To automatically populate an array in PHP based on files in a directory, you can use the `scandir()` function to retrieve an array of files in the directory. You can then loop through the array and filter out any unwanted files or directories. Finally, you can populate a new array with the remaining file names.
$directory = '/path/to/directory';
$files = array_diff(scandir($directory), array('..', '.'));
$fileList = array();
foreach ($files as $file) {
if (is_file($directory . '/' . $file)) {
$fileList[] = $file;
}
}
print_r($fileList);