Use slice?
```php
foreach ($units->slice(0, $quantity) as $unit) {
    $order->removeInventoryUnit($unit);
}