array_find on a collection that should have been indexed

Replacing a foreach with array_find made the code shorter and left the actual problem in place.

// the tidy version
$line = array_find($order->lines, fn (Line $l) => $l->sku === $sku);

// inside a loop over 400 SKUs, on an order with 200
// lines: 80,000 comparisons.

// the fix that mattered
$bySku = array_column($order->lines, null, 'sku');
$line  = $bySku[$sku] ?? null;

A new function makes a linear scan pleasant to write, which is exactly when it is worth asking whether the scan should be there. The reading improvement is real and it made the quadratic behaviour easier to overlook — the version with the explicit foreach at least looked like work.