title: Read two csv files and concatenate their two columns into new file with php
body: <p>I want to concatenate two CSV files:</p>
  
  <p><strong>url.csv :</strong></p>
  
  <p>www.text.com/test.html</p>
  
  <p>www.text.com/test1.html</p>
  
  <p>www.text.com/test2.html</p>
  
  <p><strong>color.csv :</strong></p>
  
  <p>Red</p>
  
  <p>Black</p>
  
  <p>Pink</p>
  
  <p>result should like :</p>
  
  <p>www.text.com/test.html?color=Red</p>
  
  <p>www.text.com/test1.html?color=Red</p>
  
  <p>www.text.com/test2.html?color=Red</p>
  
  <p>www.text.com/test.html?color=Black</p>
  
  <p>www.text.com/test1.html?color=Black</p>
  
  <p>www.text.com/test2.html?color=Black</p>
  
  <p>my final code :</p>
  
  <pre><code>$url_csv = "cache_build_urls_file.csv";
  $url_csv_resource = fopen($url_csv,"r");
  
  $color_csv = "colors_file.csv";
  $color_csv_resource = fopen($color_csv,"r");
  
  $new_color = "color_cache_build_urls_file.csv";
  $outputBuffer = fopen($new_color, 'w');
  
  $result = $urls = $colors = array();
  
  if (($handle = fopen($url_csv, "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      $urls[] = $data[0];
  }
  fclose($handle);
  }
  if (($handle = fopen($color_csv, "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      $colors[] = $data[0];
   }
  fclose($handle);
  }
  foreach( $urls as $url ) {
  foreach( $colors as $color ) {
      $result[] = $url.'?color='.$color;
  
      }
  }
  
  
  foreach($result as $val) {
      $arr[0] = $val;
       fputcsv($outputBuffer,$arr);
  }
  fclose($outputBuffer);
  </code></pre>