Here's the project: I'm creating a PHP script to optimize images in a folder. I'm grabbing all the JPGs from the folder, getting their modified date and filename, and pushing them into an array; this array is being iterated through for the compression, as well as eventually being output into a json file for later checks to make sure I don't optimize an image again if it isn't needed.
Problem: my inner arrays are empty when I print_r.
I'm not as strong a backend dev as I am frontend, so I'm a little weak with multidimensional associative arrays in PHP.
if (is_dir($imgFolder)){
if ($dh = opendir($imgFolder)){
$imgIndex = 0;
while (($file = readdir($dh)) !== false){
if (strpos($file, '.jpg') !== false){
$imgDate = filemtime($imgFolder . $file);
array_push($imgFiles,
array($imgIndex => array(
[lastmod] => $imgDate, [filename] => $file)
)
);
$imgIndex++;
}
}
closedir($dh);
}
}
Basically, I want the values to be like this..
[0]
[lastmod]=>date1
[filename]=>file1.jpg
[1]
[lastmod]=>date2
[filename]=>file2.jpg
[2]
[lastmod]=>date3
[filename]=>file3.jpg