<?php
use someapiconnectionPersons;
try {
require_once('autoload.php');
$PersonsAPI = new Persons();
$data = $PersonsAPI->get();
if (!empty($data)) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=offline_persons.csv');
$fp = fopen('php://output', 'wb');
fputcsv($fp, array_keys($data));
foreach ($data as $line) {
$val = explode(",",$line);
fputcsv($fp, $line);
}
fclose($fp);
} else {
echo "No data found";
}
} catch (Exception $e) {
echo "Error fetching data: " . $e->getMessage();
}
OUTPUT Error is: PHP Fatal error: Uncaught TypeError: fputcsv(): Argument #2 ($fields) must be of type array
Stack Trace: fputcsv(Resource id #15, Object(APIEthosPersons), ‘,’)
Followed by a list of numbers
0,1,2,3,4,5,….
New to php any help on where I am going wrong would be appreciated
New contributor