Multidimensional Arrays
Posted: Sat May 19, 2007 6:25 pm
Here's what I'm trying to do. Search a given directory for all the pdf files. They're all stored with names of dates for each file. The format is mmddyyyy.pdf. Is what I did was put all the pdf files in the directory into a multidimensional array with their filename, day, month, and year. Now I want to insert them as links into a calendar that I have. The format for the calendar to add linked days looks like this:
The first number is the day of that month: 2,3,8,22. The 01022007.pdf etc is the link to the file. and linked-day represents its a day that has an event on it and is linked.
This array is a small piece of the $days array listed above, displaying the 2nd day link.
Now what I need to do is find all the files that have a day in each month. So all the days in month '01' and sort them together. Then I need to create an array like the one above from the multidimensional array:
Here's the code to put all the files into an multidimensional array:
Any help is greatly appreciated I'm trying to finish up this project and this is the last part.
Code: Select all
$days = array(
2=>array('01022007.pdf','linked-day'),
3=>array('01032007.pdf','linked-day'),
8=>array('01082007.pdf','linked-day'),
22=>array('01222007.pdf','linked-day'),
);Code: Select all
Array
(
[2] => Array
(
[0] => 01022007.pdf
[1] => linked-day
)
)Now what I need to do is find all the files that have a day in each month. So all the days in month '01' and sort them together. Then I need to create an array like the one above from the multidimensional array:
Code: Select all
Array
(
[] => Array
(
[filename] => 09112006.pdf
[day] => 11
[month] => 09
[year] => 2006
)
[1] => Array
(
[filename] => 11212006.pdf
[day] => 21
[month] => 11
[year] => 2006
)
[2] => Array
(
[filename] => 05022007.pdf
[day] => 02
[month] => 05
[year] => 2007
)
)Code: Select all
$dir = 'notices';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file == (substr($file, -3) == 'pdf')) {
if (is_dir("$dir/$file")) {
$folder_array[] = strtolower($file);
} else {
$file_array[$i]['filename'] = strtolower($file);
$file_array[$i]['day'] = substr($file, 2,2);
$file_array[$i]['month'] = substr($file, 0,2);
$file_array[$i]['year'] = substr($file, 4, 4);
}
}
$i ++;
}
closedir($handle);
}