RD Ward
RD Ward

Reputation: 6737

Trying to count existing files with array walk, getting "Only variables can be passed by reference"

existingReports[$i] 
= count(array_walk(file_exists,$data['reports'][$i])); 

Is something wrong with this statement?

For example

print_r($filename[3]);

[0] => uploads/2011-05-10%20Philippines%20Philippine%20storm%2022%20dead.pdf 

[1] => uploads/2011-05-10%20Philippines%20Philippine%20storm%2022%20dead.pdf 

[2] => uploads/2011-05-10%20Philippines%20Philippine%20storm%2022%20dead.pdf 

[3] => uploads/2011-05-12%20Philippines%20Nestle%20noodles.jpg 

[4] => uploads/2011-05-12%20Philippines%20Nestle%20noodles.jpg 

[5] => uploads/2011-05-12%20Philippines%20Nestle%20noodles.jpg 

[6] => uploads/2011-05-13%20Algeria%20TESTTEST 

Obviously I am checking to see which of those reports exists, I will also need to dedupe them now that I am looking at this.

Upvotes: 0

Views: 118

Answers (1)

mario
mario

Reputation: 145492

You probably want to use array_map array_filter here instead:

= count(array_filter($data['reports'][$i], "file_exists"));

Of course, the first parameter still needs to contain an array. If it matches your example output of print_r($filename[3]); it should work however.

Upvotes: 1

Related Questions