Created
May 9, 2016 05:36
-
-
Save guweigang/7d458f2f14f7dcf41f34478e589cea23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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