0

I have six CSV files that I want to convert into individual arrays and then intersect those arrays to see all of the values that are similar in each. I have this so far:

 $directory = "/csv/CSS_AUDIT/";

 if (! is_dir($directory)) {
     exit('Invalid directory path');
 }

 $files = array();

 foreach (scandir($directory) as $file) {
     if ('.' === $file) continue;
     if ('..' === $file) continue;

     $files[] = $file;

      $row = 1;

     if (($handle = fopen("/csv/CSS_AUDIT/$file", "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             $num = count($data);
             $row++;
             for ($r=0; $r < $num; $r++) {
                 echo $data[$r];
                 if (!empty($data[$r])) 
                    echo "\n";
             }
         }
         fclose($handle);
     }

 }

Right now it is looping through the files and giving me everything in one large array and I'm just kinda stuck. Any advice on how to achieve What I am trying to do?

1 Answer 1

0

If the files aren't too big, you can load them into an array and either check that such value doesn't exist in the array before adding to it, or running array_unique() when you're done. See this for a reference.

If the files are too big, you'll have to use some other more complicated and time-consuming methods (such as reading the (hopefully sorted) output each time before inserting new line).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.