I'm currently working on a project where I have to access the objects from Audience Segments and export the data that comes together with it in an excel format.
I'm still new to PHP and I can't seem to figure my way around this. Here's a sample code
if ($page->getResults() !== null) {
$totalResultSetSize = $page->getTotalResultSetSize();
$i = $page->getStartIndex();
$myfile = fopen($fileName.".xls", "a") or die("Unable to open file!");
foreach ($page->getResults() as $audienceSegment) {
$id = $audienceSegment->getId(); //long
$name = $audienceSegment->getName(); //string
$size = $audienceSegment->getSize(); //long
fputcsv($myfile,"$id, $name, $size");
$i++;
}
fclose($myfile);
}
As you can see in the code, I'm trying to export the data from the variables $id
, $name
, and $size
. Since I'm using fputcsv
, I'm getting this error,
**Warning: fputcsv() expects parameter 2 to be array**
Hence, that's the reason why I want the objects to come in an array. Can someone help me?