-5

I have an array with keys 1, 2 and 3.

I would like to rearrange elements in a circular manner. So it will be like this:

1 => parent
2 =>  child
3 =>  child

2 =>  parent
1 =>  child
3 =>  child

3 =>  parent
1 =>  child
2 =>  child

Thanks for your helps.

Rahul
  • 18,271
  • 7
  • 41
  • 60
Stephen
  • 1
  • 1
  • I don't understand the sequence, `1 2 3` -> `2 1 3` -> `3 1 2`. Are you looking for all permutations or ...? – Dave Chen Feb 26 '16 at 07:39
  • Exactly, but result limit only three possibility based on how may item in array, not six. – Stephen Feb 26 '16 at 07:43
  • Okay there's still no consistency with that sequence. `{1,2,3} {1,3,2} {2,1,3} {2,3,1} {3,1,2} {3,2,1}` Is all of them, do you just want to stop after three items? You should explain what exactly you need this for. – Dave Chen Feb 26 '16 at 07:48
  • http://stackoverflow.com/a/10223120/4229270 – Sinto Feb 26 '16 at 07:51
  • Yes I want to stop after the three parent listed. – Stephen Feb 26 '16 at 08:12

1 Answers1

0

Answering my own question,

$parent = array('1','2','3');
foreach($parent as $key => $value) {
    echo $value ."\n";
    $p = $parent;
    unset($p[$key]);
    foreach($p as $k => $v) {
        echo '     ' . $v ."\n";
    }
}
Stephen
  • 1
  • 1