从现有数组创建多个数组[重复]

This question already has an answer here:

I am stuck at one place where I have 3 arrays as below:

$c = array("red","green","blue");
$s = array("12","13","14");
$l = array("3","4","5");

Based on this array I need arrays like:

$one = array("red", "12", "3");
$two = array("red", "12", "4");
$three = array("red", "12", "5");
$three = array("red", "13", "3");
...........

Same I need to create array which include all combinations of above 3 arrays.

I have tried to create by looping through all, but can anyone tell me a better solution or existing php function for this.

</div>

There is a helper class for that:

https://github.com/noptic/co3/blob/master/src/daliaIT/co3/util/generator/ArrayGenerator.php

The package is no longer mantained but you can remove the 'IInject' interface and the "inject" method and use it as a standalone class.

The class can be iterated with foreach without creating all the combinations in memory.

If you need a "real" array call the "toArray" method