<?php
$products = [1, 2, 3, 4, 5];
$vendors = ["Amazon", "Newegg", "Frys"];
$combinations = Array();
function pc_permute($items, $perms = array()) {
if (empty($items)) {
//echo join(' ', $perms) . "</br>";
//return $perms;
array_push($combinations, $perms);
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems, $newperms);
}
}
}
pc_permute($products);
var_dump($combinations);
preferences:
40.24 ms | 402 KiB | 5 Q