i am iterating an array with more than 3000 items in it array looks something like that:
[
[
'id' => 1,
'type' => 'income'
'amount' => 10
],
[
'id' => 2,
'type' => 'expense',
'amount' => 20
],
.......
]
while iterating i call functions that manipulate another array in the same class something like that:
$this->data->revenue->each(function($row) use($user)
{
if ($row->isIncome())
{
$this->addRevenueRowToColumn($row, 'income');
$this->addRevenueRowToColumn($row, 'total');
}
if ($row->isExpense())
{
$this->addRevenueRowToColumn($row, 'expense');
$this->subtractRevenueRowToColumn($row, 'total');
}
}
this is what the functions do:
protected function addRevenueRowToColumn(&$row, $columnName)
{
$this->report['byMonth'][$row->getMonthTableKey()]['byDepartment'][$row->department_id][$columnName] += $row->amount;
$this->report['byMonth'][$row->getMonthTableKey()]['total'][$columnName] += $row->amount;
$this->report['totals']['byDepartment'][$row->department_id][$columnName] += $row->amount;
$this->report['totals']['total'][$columnName] += $row->amount;
}
protected function subtractRevenueRowToColumn(&$row, $columnName)
{
$this->report['byMonth'][$row->getMonthTableKey()]['byDepartment'][$row->department_id][$columnName] -= $row->amount;
$this->report['byMonth'][$row->getMonthTableKey()]['total'][$columnName] -= $row->amount;
$this->report['totals']['byDepartment'][$row->department_id][$columnName] -= $row->amount;
$this->report['totals']['total'][$columnName] -= $row->amount;
}
it takes about 11 seconds to process the data and display it
what should i do? thanks in advance!