it's the first time I try to export a csv with php and I'm having a problem, I'm trying to export all information from an array in CSV form, but when I'm doing the foreach to organize the information that goes to the array, after exporting the information only appears in the csv if I use the "ECHO" during the array, but that bothers me because it consumes more memory. How can I put the information in csv without using "Echo" during foreach ?
my code.
echo "name" . ',' . "lastname" . ',' . "email" . ',' . "id" . ',' . "create" . ',' . "group" . ',' . "region" . ',' . "city" . ',' . "postcode" . ',' . "telephone" . "\n";
$clients = array();
foreach ($collection as $item) {
$users = Mage::getModel('customer/customer')->load($item['entity_id']);
$defaultBillingAddress = Mage::getModel('customer/address')->load($users->getData('default_billing'));
echo $clients[] = $users->getData('firstname');
echo $clients[] = ',' . $users->getData('lastname');
echo $clients[] = ',' . $users->getData('email');
echo $clients[] = ',' . $users->getData('entity_id');
echo $clients[] = ',' . $users->getData('created_at');
echo $clients[] = ',' . $defaultBillingAddress->getData('region');
echo $clients[] = ',' . $defaultBillingAddress->getData('city');
echo $clients[] = ',' . $defaultBillingAddress->getData('postcode');
echo $clients[] = ',' . $defaultBillingAddress->getData('telephone') . "\n";
break;
}
$f = fopen('php://output', 'a');
foreach ($clients as $clusters) {
fputcsv($f, $clusters);
}
fclose($f);