merge several arrays to one multidimensional

Hello. I have a list of numbered folders. In each folder there is a lot of .jpg files. I get a list of all including image files from this directories with two glob functions dynamically. I store a list of directory paths and filenames into two separates arrays called $DIR[] and $files[].
[php]<?php
//FOLDERS
//create array for each directory
$pathDIR = “dirname/”;
$DIR = Array(
);
//store directory names into an array with foreach
foreach (glob($pathDIR . ‘/[0-30]’, GLOB_ONLYDIR) as $dirname) {
$DIR[] = $dirname;
}
//display path directories
for($a = 0; $a < count($DIR); $a++) {
echo $DIR[$a] . “
”;
}
//FILES
//create array for each directory
$pathFILE = Array();
//create array for files
$files = Array();
//loop start
for($b = 1; $b <= count($DIR); $b++) {
$pathFILE[$b] = “dirname/” . $b . “/”;
//store files in array with foreach
foreach(glob($pathFILE[$b] . '
.jpg’) as $filename) {
$files[] = $filename;
}
}
//display files
for($c = 1; $c <= count($files); $c++) {
echo $files[$c-1] . “
”;
}
?>[/php]

I’ve tried to combine two arrays in one multidimensional array with:

[php]array_push ($DIR, $file);[/php]

to display array values I’ve tried with a pair of loops:

[php]
for($d = 0; $d <= count($DIR); $d++) {
for($e = 0; $e <= count($DIR[$d]); $e++) {
echo $DIR[$d][$e] . “
”;
}
} [/php]

Unfortunately array values are not properly show. Also, a notice indicate undefined offset .

Thanks a lot for your help.

So the goal is a 2 dimensional array, with the directory as the key?

Sponsor our Newsletter | Privacy Policy | Terms of Service