配列に3000を超えるアイテムを含む配列を反復しています。次のようになります。
[
[
'id' => 1,
'type' => 'income'
'amount' => 10
],
[
'id' => 2,
'type' => 'expense',
'amount' => 20
],
.......
]
繰り返しながら、同じクラスの別の配列を操作する関数を次のように呼び出します。
$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');
}
}
これは関数が行うことです:
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;
}
データを処理して表示するのに約 11 秒かかります
私は何をすべきか?前もって感謝します!