folder; $files = new \DirectoryIterator($folder); $output = []; foreach ($files as $file) { if ($file->isDir() or $file->getExtension() != 'csv') { continue; } $bank = 'unknown'; $text = trim(file_get_contents($file->getRealPath())); if (str_contains($text, 'SCOTIABANK')) { $bank = 'Scotiabank'; } if (str_contains($text, 'BICE')) { $bank = 'BICE'; } $data = explode(PHP_EOL, $text); array_walk($data, function(&$item) { $item = trim($item, '; '); if (str_contains($item, ';') !== false) { $item = explode(';', $item); } }); $output []= ['bank' => $bank, 'filename' => $file->getBasename(), 'data' => $data]; } return $this->build($output); } protected function build(array $data): ?array { return $data; } }