What are the potential pitfalls of trying to store images from a directory in a multidimensional array in PHP?

One potential pitfall of trying to store images from a directory in a multidimensional array in PHP is that it can consume a lot of memory if there are a large number of images. To solve this issue, you can store the image paths in the array instead of the actual image data.

// Get all files from a directory and store their paths in a multidimensional array
$directory = 'images/';
$images = [];

foreach (glob($directory . '*') as $file) {
    $images[] = $file;
}

print_r($images);