1

I apologize first, but I've been coding for about 8 hours today to get this last thing done.

Code.

$a = array('a', 'c', 'b');

$c = array('a', 'c', 'b');

foreach(array_combine($a, $c) as $k => $v) {
  echo $k.$v;
}

resulting in: aa, bb, cc

but I want to get@

aa, ac, ab
ba, bc, bb
ca, cc, cb
AMIC MING
  • 6,306
  • 6
  • 46
  • 62
  • `array(a, c, b);` isn't even valid syntax. – Waleed Khan Feb 08 '13 at 23:50
  • I've defined it. Yea i've created loop and get like: a, aa, ab, ac, ba, bb, bc, ca, cb, cc, c. Remind i need only double(aa/cc) not a or c or b. If there is single output it might a problem. – user2056034 Feb 09 '13 at 00:11
  • Does my nested loop answer below not work? It shouldn't generate an single value, only doubles. – lwitzel Feb 09 '13 at 00:13

2 Answers2

4

If you want all permutations, then I'm not sure you want to use array_combine(). Just use nested loops, like this:

$a = array('a', 'c', 'b');
$c = array('a', 'c', 'b');

foreach($a as $v1){
  foreach($c as $v2) {
    echo $v1.$v2;
  }
}
lwitzel
  • 591
  • 5
  • 15
1

I recommend you to use foreach function. Don't use array_combine().

function cloop($a, $c) {

$a = array('a', 'b', 'c');
$c = array('d', 'e', 'f');

foreach($a as $A){

  foreach($c as $B) {

    $ab = $A.$B;

  }

}

return $ab;

}
Fujael
  • 107
  • 1
  • 10