How can dynamic image filenames be added to an inner array within a multidimensional array in PHP?

When adding dynamic image filenames to an inner array within a multidimensional array in PHP, you can achieve this by creating a new inner array for each image filename and then adding it to the main multidimensional array. This can be done by looping through the image filenames and pushing them into the inner array before pushing the inner array into the main multidimensional array.

// Sample array of image filenames
$imageFilenames = ['image1.jpg', 'image2.jpg', 'image3.jpg'];

// Initialize an empty multidimensional array
$imagesArray = [];

// Loop through the image filenames and add them to the inner array
foreach ($imageFilenames as $filename) {
    $innerArray = [];
    $innerArray['filename'] = $filename;
    
    // Add any other dynamic data related to the image here
    
    // Push the inner array into the main multidimensional array
    $imagesArray[] = $innerArray;
}

// Print the multidimensional array
print_r($imagesArray);