Hello,
I have a CSV file that looks like this:
"Account","State","Zip","Email","Birth Date","Favorites","Balance"
with data rows in them. I need to calculate total balances aggregated by state, need to get output in .txt flle like:
State, Balance
value, value
this is how I started :
$inputfile = 'input.csv';
$inputHandle = fopen($inputfile, "r");
$output = array();
while (($data = fgetcsv($inputHandle, 1024, ",")) !== FALSE){
foreach($data as $line) {
list($state, $balance) = $data;
$state = trim($state);
$balance = trim($balance);
$output[$state] += (int)$balance;
file_put_contents('summary.txt', var_export($output, TRUE));
}
}
I get unidentified inxex errors on
$output[$state] += (int)$count;
May be i make some mistake in line:
list($state, $balance) = $data;
Could someone maybe propose a better, more convinient solution here?