Skip to content

Instantly share code, notes, and snippets.

@AdamJonR
AdamJonR / gist:5278480
Last active December 15, 2015 14:59
Iteration of work from specific, hard-coded instance of algorithm to generic function. In this case, the algorithm requested (http://stackoverflow.com/questions/12293870/algorithm-to-get-all-possible-string-combinations-from-array-up-to-certain-lengt) involved creating all possible combinations from an array of values given a minimum and maximum…
// array from which to create combinations
$arr = ['a','b','c','1','2','3'];
// pick specific case of minimum and maximum length of 5 and just get it done
function combinationsOf5_1($arr) {
$results = [];
for ($i = 0; $i < count($arr); $i++) {
$first = $arr[$i];
for ($j = 0; $j < count($arr); $j++) {