I'm having trouble figuring out how best to get the logic correct for the following:
- I'm 'scanning' a directory for a list of file names and putting the filenames in an array. (no problem here).
- I'm then 'looking' in the array for two particular filenames. I'm doing this by using in_array (no problem here).
- When I find either of the filenames I need to open the files and do some work (once again no problem here).
The problem I'm having is figuring out the logic/flow for dealing with both files? What i mean is that my array could contain neither of the files I'm looking for, either one of the files, or both. Looking for ideas for on the best way to deal with the three scenarios:
- No files.
- Either one of the files.
- Both files.
Thanks.
//get the list of files in the directory into an array
$dir = ".";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
//check to see if the array has files in it
if (!$files){
//no then stop
die;
//yes then start the conversion
} else {
// check to see if the file we want is there
if (in_array($specificfile1, $files)) {
echo "found the file";
} else {
echo "not there";
}
}