![]()
Snippets of A |
|
|
What are snippets? |
|
function arrayCombinator(&$array){ if(!is_array($array)){return $array;/*or php sizeof() matches Strings too!*/}; $output=array(); $L=sizeof($array); $i1=-1; while(++$i1<$L){ $compare=array_shift($array); $L2=sizeof($array)-$i1; $i2=-1; while(++$i2<$L2){/*kernel is here:*/ $output[]=array($compare, $array[$i2]); } array_push($array, $compare); } return $output; /*keep comment to use freely: http://www.fullposter.com/?1*/}Remove colors
$output variable related parts, and manipulate directly the $compare $array[$i2]Remove colors items with code of your own: in fact, those items are your combinations in progress.
range(0,29) (whereas 29 is 30-1) and pass it to this function; then, to grab the combinations from the input array you may just use the indexes of the firstly produced array as a map (arguably to serialize for later use): so you run the function only once - in a lifetime, at least for all arrays whose length is either equal or inferior to 30.
$afoo=array(0,1,2,3,4,5,6); print_r( arrayCombinator($afoo) );Remove colors