mirror of
https://github.com/devcode-it/openstamanager.git
synced 2024-12-12 08:26:20 +01:00
29 lines
489 B
PHP
29 lines
489 B
PHP
|
<?php
|
||
|
|
||
|
/**
|
||
|
* Genera il prodotto cartesiano tra gli elementi dell'array di input.
|
||
|
*
|
||
|
* @param $input
|
||
|
*
|
||
|
* @return array|array[]
|
||
|
*/
|
||
|
function cartesian($input)
|
||
|
{
|
||
|
$result = [[]];
|
||
|
|
||
|
foreach ($input as $key => $values) {
|
||
|
$append = [];
|
||
|
|
||
|
foreach ($result as $product) {
|
||
|
foreach ($values as $item) {
|
||
|
$product[$key] = $item;
|
||
|
$append[] = $product;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$result = $append;
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
}
|