Key Value pairs not displayed in rows

I am trying to write code to read a list of names and then read all the

tags related to each name. The tags are then collected in $ancestor and written to an output file. The intent is that the output file can arranged so that key=>value pairs can be sorted into rows. The first row is the header and all subsequent rows are Values. <?php
    //this loop goes through our "pages" 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->find('td') as $element){
       //and put the value in our Ancestor array
       $ancestor[] = $element->innertext.",";   
       //display the full Ancestor array to the page
       //OPen the file called FILE.csv with 'w'=write permissions
       $handle = fopen('export.csv', 'w');
       fputcsv($handle, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5','Column 6','Column 7','Column 8','Column 9','Column 10','Column 11','Column 12','Column 13',));
           foreach ($ancestor as $fields) {
           fputcsv($handle, (array) $fields);


Sponsor our Newsletter | Privacy Policy | Terms of Service