count($files), 'clean' => 0, 'dirty' => [], 'total_remaining' => 0]; foreach ($files as $f) { $fp = "/var/www/html/$f"; if (!file_exists($fp)) { $R['dirty'][] = ['f'=>$f,'err'=>'missing']; continue; } $c = substr_count(file_get_contents($fp), '11435'); if ($c === 0) $R['clean']++; else { $R['dirty'][] = ['f'=>$f,'count'=>$c]; $R['total_remaining'] += $c; } } echo json_encode($R, JSON_PRETTY_PRINT);