I have a function that retrieves file names in some directory. The directory has multiple PDF files.
I want to assign a key to each of the PDF files I gathered, where the key is the number that is located between - and .pdf in the filename.
For instance I have 3 PDF files:
abc-1.pdf
abc-2.pdf
abc-3.pdf
What I want to have:
1 => abc-1.pdf,
2 => abc-2.pdf,
3 => abc-3.pdf
My function is currently this:
function getPDFs($PDF_DIR_NAME, $PDF_TOKEN) {
if ($PDF_TOKEN == null || $PDF_TOKEN == '') {
return null;
} else {
$getPDFVersions = $PDF_TOKEN.
"*";
$dirs = glob($PDF_DIR_NAME.
'/'.$getPDFVersions);
$files = array();
foreach($dirs as $d) {
if (filesize($d) > 200) {
$files[] = basename($d);
}
}
return $files;
}
}
How can I assign keys for each PDF document?
$files[$key] = ..._, as in your comment. Your examples show a-though. Not too important, but you might want to be consistent. Also, I wrote up a bit of a guide for you but left the actual implementation to you.