<?php
$products = [1, 2, 3, 4, 5];
$vendors = ["Amazon", "Newegg", "Frys"];
$product_combinations = array();
$vendor_combinations = array();
function pc_permute($items, &$combinations, $perms = array()) {
if (empty($items)) {
$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, $combinations, $newperms);
}
}
}
// Build product combinations
//pc_permute($products, $product_combinations);
// Build vendor combinations
pc_permute($vendors, $vendor_combinations);
var_dump($vendor_combinations);
preferences:
41.32 ms | 402 KiB | 5 Q