title: Why is "fputcsv" output a single column instead of multiple columns and rows
body: <p>I am an absolute beginner with PHP. My problem is twofold, first I have a list of ancestor names and each name has 13 key =&gt; value pairs. I need my output to have a single row of headers ($keys) and mutiple rows of matching $values. My code at present repeats the header keys with each name and all the output is in one column. I think I need to exclude the  tag for the headers and place them separately in the CSV.`
  I have looked at similar problems in Stackoverflow and tried to adopt their resolutions without success.</p>
  <pre><code>
            include_once('_inc/simple_html_dom.php');
  
        //create an array of all URLs we need to target
        $pages = array(  
          &quot;http://fammilytree.loc/surnames/A%20Surnames/Adams/James%20Adams%201864.php&quot;,
          &quot;http://familytree.loc/surnames/A%20Surnames/Adams/John%20Adams%201901.php&quot;,
          &quot;http://familytree.loc/surnames/A%20Surnames/Anderson/Jeals%20Anderson%201718.php&quot;,
          &quot;http://familytree.loc/surnames/A%20Surnames/Arnett/Ann%20Arnett%201781.php&quot;);
  
       //We are initializing an array to hold the values of each &lt;TD&gt; from an ancestor's page
        $ancestor = array();
  ?&gt;
  
  &lt;html&gt;
      &lt;body&gt;
          &lt;?php
          
          //this loop goes through our &quot;pages&quot; array and then for each page in the array...
          foreach($pages as $page){
              //...calls the function which pulll all of the HTML from the page into an array 
              $html = file_get_html($page);
          
              //I think we need a multi-dimensional array, using name of ancestor as index for next array
              // $ancestor = array()
     
              
              
          // then FOR EACH element in the array of HTML, find the TD value
             foreach($html-&gt;find('td') as $element){
             //and put the value in our Ancestor array
             $ancestor[] = $element-&gt;innertext.&quot;,&quot;;   
             }
                 
             }
             //display the full Ancestor array to the page
             print_r($ancestor);
             
             
             //OPen the file called FILE.csv with 'w'=write permissions
             $handle = fopen('export.csv', 'w');
             
                 foreach ($ancestor as $fields) {
                    
                 fputcsv($handle, (array) $fields);
                 }
                 fclose($handle);          
          ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;```
  </code></pre>