Skip to content

Instantly share code, notes, and snippets.

@kdes70
Created July 12, 2018 02:52
Show Gist options
  • Save kdes70/2a2f64324851eea752396ea14b27c97b to your computer and use it in GitHub Desktop.
Save kdes70/2a2f64324851eea752396ea14b27c97b to your computer and use it in GitHub Desktop.
декартова произведения
function cartesian(array $input)
{
$result = [[]];
foreach ($input as $key => $values) {
$append = [];
foreach ($values as $value) {
foreach ($result as $data) {
$append[] = $data + [$key => $value];
}
}
$result = $append;
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment