2021-08-31 15:46:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Genera il prodotto cartesiano tra gli elementi dell'array di input.
|
|
|
|
*
|
|
|
|
* @param $input
|
|
|
|
*
|
|
|
|
* @return array|array[]
|
|
|
|
*/
|
2023-12-06 16:48:54 +01:00
|
|
|
if (!function_exists('cartesian')) {
|
|
|
|
function cartesian($input)
|
|
|
|
{
|
|
|
|
$result = [[]];
|
2021-08-31 15:46:14 +02:00
|
|
|
|
2023-12-06 16:48:54 +01:00
|
|
|
foreach ($input as $key => $values) {
|
|
|
|
$append = [];
|
2021-08-31 15:46:14 +02:00
|
|
|
|
2023-12-06 16:48:54 +01:00
|
|
|
foreach ($result as $product) {
|
|
|
|
foreach ($values as $item) {
|
|
|
|
$product[$key] = $item;
|
|
|
|
$append[] = $product;
|
|
|
|
}
|
2021-08-31 15:46:14 +02:00
|
|
|
}
|
2023-12-06 16:48:54 +01:00
|
|
|
|
|
|
|
$result = $append;
|
2021-08-31 15:46:14 +02:00
|
|
|
}
|
|
|
|
|
2023-12-06 16:48:54 +01:00
|
|
|
return $result;
|
2021-08-31 15:46:14 +02:00
|
|
|
}
|
2023-12-06 16:48:54 +01:00
|
|
|
}
|