bentools/cartesian-product
Generate the cartesian product (all combinations) from a multidimensional array with a low-memory iterator. Supports dynamic values via closures that can inspect the partial combination. Iterate results or dump them to an array when needed.
Adopt if:
filter() method.Look elsewhere if:
\Countable (e.g., custom generators without size hints).Avoid if:
For Executives: *"This package eliminates the need to manually code complex combinatorial logic—saving development time and reducing bugs. For example, if we’re building a dynamic product configurator (like a car customization tool with 5 options each having 3 variants), it can instantly generate all 243 possible combinations without custom code. This enables faster feature delivery for use cases like:
For Engineers: *"A high-performance, memory-efficient solution for generating Cartesian products in PHP 8.2+. Key benefits:
filter() to exclude invalid combinations or each() to transform results (e.g., into Eloquent models).// Generate all product variants for an e-commerce bundle
$variants = combinations([
'color' => ['red', 'blue'],
'size' => ['S', 'M', 'L'],
])->each(fn($combo) => new ProductVariant($combo));
```*
**For Product Managers**:
*"This tool lets us ship features faster by automating combinatorial logic. For example:
- **Dynamic forms**: Generate all valid field combinations for user inputs.
- **Content personalization**: Create tailored experiences based on user attribute combinations.
- **Reporting**: Automate multi-criteria analysis without manual SQL joins.
It’s a force multiplier for teams building scalable, data-driven products."*
How can I help you explore Laravel packages today?