is it possible to dynamically set the level of for loop nesting

Posted by galaxy on Stack Overflow See other posts from Stack Overflow or by galaxy
Published on 2010-03-27T13:55:47Z Indexed on 2010/03/27 14:03 UTC
Read the original article Hit count: 247

Filed under:
|
|

I'm working out an algorithm to get permutations like

123
132
213
231
312
321

I'm doing it using nested foreach loops.

for (..) {
    for(..) {
        for(..) {
           echo $i . $j . $k . "<br />";
        }   
    }
}

Problem is those # of nested loops are optimized for 3-spot permutations. How can I could I dynamically set the number of nested for loops to generate 4-letter or 5-letter permutations?

© Stack Overflow or respective owner

Related posts about php

Related posts about for-loop