3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getAllCombinations(array $arr, int $n, array $selected = [], int $startIndex = 0): array { if (!$n) { return [array_merge($selected, [array_product($selected)])]; // generate payload } $result = []; $count = count($arr); for ($i = $startIndex; $i < $count; ++$i) { array_push( $result, ...getAllCombinations($arr, $n - 1, array_merge($selected, [$arr[$i]]), $i + 1) ); } return $result; } $primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]; var_export(getAllCombinations($primes, 4));

Abusive script

This script was stopped while abusing our resources


preferences:
23.99 ms | 407 KiB | 5 Q