0, 'ram' => 0, 'disk' => 0]; if (!$item->addons) { return $totals; } foreach ($item->addons as $orderAddon) { $addon = $orderAddon->addonItems; if (!$addon) { continue; } $name = strtolower(trim((string) $addon->name)); $qty = (int) $orderAddon->qty; switch ($name) { case 'cpu': $totals['cpu'] += $qty; break; case 'ram': $totals['ram'] += $qty; break; case 'disk': case 'ssd': $totals['disk'] += $qty; break; } } return $totals; } }