I'm trying to accomplish the following but I can't seem to get it right. And even if I would, I don't think I'm doing it the right way.
Let's say I have this array:
$array = array(
array(1, 2, 3),
array(1, 2, 3),
array(1, 2, 3)
);
Now I want to get all permutations of that multidimensional array, but every 'subarray' must still have a 1, 2 and 3. So these are ok:
$array = array(
array(2, 1, 3),
array(1, 2, 3),
array(1, 2, 3)
);
$array = array(
array(2, 3, 1),
array(1, 2, 3),
array(1, 2, 3)
);
But this is not:
$array = array(
array(3, 3, 3),
array(1, 2, 1),
array(1, 2, 2)
);
I've tried quite a bit, but all that I keep getting back to is a MASSIVE amount of for-loops. And that doesn't seem like the right way to accomplish this.
I hope someone can help!
I don't get what you want - and you cannot express clearly what you want ... but this creates at least what you have given as examples.
$array = array(
array(1, 2, 3),
array(1, 2, 3),
array(1, 2, 3)
);
foreach ($array AS $key => $values) {
shuffle($array[$key];
}
var_dump($array);
0 comments:
Post a Comment