Home » Php » php – Gravity forms: exporting two forms of entries data to one CSV file

php – Gravity forms: exporting two forms of entries data to one CSV file

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m wondering if I can export two deferent forms entries based on the submitter id but with a specific concept,
The concept is:
If the entry title from the first form == some entry field of the other form, let’s show these two entries in the exported data in one row, and so on, something like array_map in php.
I hope that you got the idea, any help to do that?
Thanks a lot,
Magdi

How to&Answers:

Use These Codes:
(first code returns data from csv file into an array)
(second code gets data from an array and save into a csv file)

function csvExporter($path) {
    $csv = array();
    $row = 1;
    if (($handle = fopen($path, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            $csv[str_pad($row,4,0,STR_PAD_LEFT)] = array();
            for ($c = 0; $c < $num; $c++) {
                $csv[str_pad($row,4,0,STR_PAD_LEFT)][$c] = $data[$c];
            }
            $row++;
        }
        fclose($handle);
    }
    return $csv;
}
function csvImporter($path,$array) {
    $csvFile = fopen($path,'w+');
    foreach ($array as $rows) {
        $eachRow = '[';
        foreach ($rows as $columns) {
            $eachRow .= '\'' . trim($columns,'\'') .'\',';
        }
        $eachRow .= ']' . PHP_EOL;
    }
    fclose($csvFile);
}