After pulling my hair out for several hours I'm close but still can't get it.
I have a PHP script that uses a glob and a foreach to compile a nested array:
$folderDir = '*/';
$folders = glob($folderDir, GLOB_ONLYDIR);
$imagesDir = 'images/';
$images = Array();
foreach($folders as $folder){
  $images[] = glob($folder. $imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
}
echo json_encode($images);
I want to get the first image from each of the glob results' sub-folders and send them to jquery (and subsequently an shtml file):
$(window).load(function() 
{
    $.getJSON('populate.php', function(data) 
    {
        $.each(data, function() 
        {
            alert(data);
        });
    });
});
For a second I had it, but as soon as I changed the Jquery to using each it would alert the array 4 times (which may have something to do with the number of images in each folder?).
I've tried about 1,000 different variations of my variables, used 1 foreach, then 2 then 1.
I'm very new to PHP and need some second opinions.
Thank you to all who can give me some guidance!!
 
     
    