V
V
Valentin2016-01-18 15:16:52
PHP
Valentin, 2016-01-18 15:16:52

Recursive function to iterate over combinations of an array?

How to write a recursive function for the below code?

$arr = array('a', 'b', 'c');
$lim = count($arr); 

for($i1 = 0; $i1 < $lim; $i1++) { 
    for($i2 = 0; $i2 < $lim; $i2++) { 
        for($i3 = 0; $i3 < $lim; $i3++) { 
       echo $arr[$i1].$arr[$i2].$arr[$i3].'<br>';
        } 
    } 
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2016-01-18
@Sanasol

www.stackoverflow.com/a/15902836

D
Denis, 2016-01-19
@prototype_denis

stackoverflow.com/a/19067884
From above link
Replace with
$output = sampling($chars, count($chars));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question