Skip to content

Instantly share code, notes, and snippets.

@guweigang
Created May 9, 2016 05:36
Show Gist options
  • Save guweigang/7d458f2f14f7dcf41f34478e589cea23 to your computer and use it in GitHub Desktop.
Save guweigang/7d458f2f14f7dcf41f34478e589cea23 to your computer and use it in GitHub Desktop.
<?php
// 会音乐
$a = [];
$a[0] = ["hui", "kuai"];
$a[1] = ["yin"];
$a[2] = ["le", "yue"];
function arr_product($a, $b)
{
$b = reset($b);
$tmp = [];
foreach ($a as $subA) {
foreach ($b as $subB) {
$tmp[] = $subA . "," . $subB;
}
}
return [$tmp];
}
function combine($a)
{
if(count($a) > 1) {
return arr_product(array_shift($a), combine($a));
} else {
return $a;
}
}
var_dump(combine($a)[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment