PHP 2D Array output all combinations
Posted
by stukerr
on Stack Overflow
See other posts from Stack Overflow
or by stukerr
Published on 2010-03-25T15:01:58Z
Indexed on
2010/03/25
15:03 UTC
Read the original article
Hit count: 407
Hi there,
I've had this problem bending my mind for a while now (head cold doesn't help either!), basically I have a PHP array which looks like this example:
$array[0][0] = 'apples';
$array[0][1] = 'pears';
$array[0][2] = 'oranges';
$array[1][0] = 'steve';
$array[1][1] = 'bob';
And I would like to be able to produce from this a table with every possible combination of these, but without repeating any combinations (regardless of their position), so for example this would output
Array 0 Array 1 apples steve apples bob pears steve pears bob
But I would like for this to be able to work with as many different arrays as possible.
Many thanks!
© Stack Overflow or respective owner