fork(47) download
  1. <?php
  2. function florg ($n, $elems) {
  3. if ($n > 0) {
  4. $tmp_set = array();
  5. $res = florg($n-1, $elems);
  6. foreach ($res as $ce) {
  7. foreach ($elems as $e) {
  8. array_push($tmp_set, $ce . $e);
  9. }
  10. }
  11. return $tmp_set;
  12. }
  13. else {
  14. return array('');
  15. }
  16. }
  17. $elems = array('A','B','C');
  18. $v = FlOrG(3, $elems);
  19. foreach($v as $child) {
  20. print $child . "\n";
  21. }
  22.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
AAA
AAB
AAC
ABA
ABB
ABC
ACA
ACB
ACC
BAA
BAB
BAC
BBA
BBB
BBC
BCA
BCB
BCC
CAA
CAB
CAC
CBA
CBB
CBC
CCA
CCB
CCC