Laravel - Collections - Method Reduce Spread

The reduceSpread method reduces the collection to an array of values, passing the results of each iteration into the subsequent iteration. This method is similar to the reduce method; however, it can accept multiple initial values:

    
    [$creditsRemaining, $batch] = Image::where('status', 'unprocessed')
            ->get()
            ->reduceSpread(function ($creditsRemaining, $batch, $image) {
                if ($creditsRemaining >= $image->creditsRequired()) {
                    $batch->push($image);
    
                    $creditsRemaining -= $image->creditsRequired();
                }
    
                return [$creditsRemaining, $batch];
            }, $creditsAvailable, collect());