Question

I have an array that contains several names of files of a folder.

If new files are added to that folder I want to get their names.

I thought it would be a good idea to compare the files to the array and create a new array with array_diff.

I've ended up with something like:

$container = array {"one","two","three"};
$allfiles = array {};

foreach(glob('./images/*.*') as $filename){
     array_push($allfiles,$filename);
 }

$newitems = array_diff($allfiles,$container);

Is this right? Is this the way you would do it?

How can I filter for file with a determined extention only to be included in $allfiles?

Was it helpful?

Solution

I think that you didn't try to parse the code, because you have syntax error, and you don't know it, by the way, you can change :

$container = array {"one","two","three"};
$allfiles = array {};

to

$container = array("one","two","three");
$allfiles = array();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top