0

Let's say I have several arrays:

$array1 = array( 'a','b','c');
$array2 = array( '1','2','3');
$array3 = array( '+','-');

As a result I'd like to have a array of all possible mixes of those arrays:

$result = array( 'a1+','a1-','a2+','a2-','b1+','b1-','b2+'...

SQL provides such operation in case of the following request:

SELECT * FROM `letters`,`digits`,`operations`

Ho can I do this in PHP?

Roman Matveev
  • 563
  • 1
  • 6
  • 22

1 Answers1

0
$permute= array();
foreach($array1 as $x)
    foreach($array2 as $y)
        foreach ($array3 as $z)
            $permute[]= $x.$y.$z;
Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • Thanks! Is it possible to convert this function to do this for any amount of arrayN-s? Please help me to build this recurring function... – Roman Matveev May 29 '13 at 20:42