How to find every possible combination of arrays in PHP

Posted by DenverZ on Stack Overflow See other posts from Stack Overflow or by DenverZ
Published on 2010-12-28T21:50:44Z Indexed on 2010/12/28 21:53 UTC
Read the original article Hit count: 312

Filed under:
|
$data = array(
'a' => array('a1', 'a2', 'a3'),
'b' => array('b1', 'b2', 'b3', 'b4'),
'c' => array('c1', 'c2', 'c3', 'c4', 'c5'));

to get

a1
a2
a3
b1
b2
b3
b4
c1
c2
c3
c4
c5

a1 b1
a1 b2
a1 b3
a1 b4
a1 c1
a1 c2
a1 c3
a1 c4
a1 c5

b1 c1
b1 c2
b1 c3
b1 c4
b1 c5
b2 c1
b2 c2
b2 c3
b2 c4
b2 c5
b3 c1
b3 c2
b3 c3
b3 c4
b3 c5
b4 c1
b4 c2
b4 c3
b4 c4
b4 c5

a1 b1 c1
a1 b1 c2
a1 b1 c3
a1 b1 c4
a1 b1 c5
a1 b2 c1
a1 b2 c2
a1 b2 c3
a1 b2 c4
a1 b2 c5
a1 b3 c1
a1 b3 c2
a1 b3 c3
a1 b3 c4
a1 b3 c5
a1 b4 c1
a1 b4 c2
a1 b4 c3
a1 b4 c4
a1 b4 c5
etc...

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays