Re: How to get all combinations

From: Date: Sun, 19 May 2002 15:02:51 +0000
Subject: Re: How to get all combinations
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-13861@lists.php.net to get a copy of this message
"Steen Rabol" <srj@compudesign.dk> wrote in message news:000501c1fe7d$e8c7f470$0701a8c0@webw03.home... > Hi > > I have 6 arrays with data and would like to have all possible > combinations > Eg. > > $a1 = array(1,2); > $a2 = array(3,4); > $a3 = array(5,6); > $a4 = array(7,8); > $a5 = array(9,10); > $a6 = array(11,12); > > the result should then be a new array like this: > > [0] = 1,3,5,7,9,11 > [1] = 1,4,5,7,9,11 > [2] = 1,6,5,7,9,11 I'm not sure I follow here... you want all possible combinations of one value from each array? ie one of (1,2) and one of (3,4) and one of (5,6) etc (64 combinations), or all combinations of 6 values from anywhere - six of (1,2, 3,4,5,6,...) (924 combinations)? I would assume the first except for [2]. The solution depends heavily on this question. Also, rather than 'returning all possible combinations' I would really strongly suggest testing each combination as it is generated, and only keep candidates which match whatever criteria you are looking for, ie "combinations which sum to a multiple of 3" or whatever. ... in fact, if you tell us more about what problem you are trying to solve by generating combinations, we might be able to suggest a better way of going about it.

« previous php.windows (#13861) next »