I need some help in generating input for my function.
I have two sets of arrays:
Products:
$products = array('prod_1'=>1,'prod_2'=>1,'prod_3'=>1,'prod_4'=>1);
Prices:
$prices = array(1,2,3);
What i would like to get, is a loop that would output all possible combinations of $products array populated by $prices:
example output
# array('prod_1'=>1,'prod_2'=>1,'prod_3'=>1,'prod_4'=>1);
# array('prod_1'=>2,'prod_2'=>1,'prod_3'=>1,'prod_4'=>1);
# array('prod_1'=>1,'prod_2'=>2,'prod_3'=>1,'prod_4'=>1);
# array('prod_1'=>1,'prod_2'=>1,'prod_3'=>2,'prod_4'=>1);
# array('prod_1'=>1,'prod_2'=>1,'prod_3'=>1,'prod_4'=>2);
...
# array('prod_1'=>1,'prod_2'=>2,'prod_3'=>2,'prod_4'=>1);
...
# array('prod_1'=>2,'prod_2'=>3,'prod_3'=>1,'prod_4'=>1);
...
#1 array('prod_1'=>3,'prod_2'=>1,'prod_3'=>3,'prod_4'=>2);
etc.
UPDATE 1
In my opinion it should work something like a clock:
- Set all values in $products to first value from $prices
- Loop thought all values from $prices for $products['prod_1']
- When you bump the and set $products['prod_1'] to $prices[0] and do point 2 for $products['prod_2'] (index+1)
- Do point 2 and 3 and go index+1, reset prev until all $products values are set to last $prices value
Output:
1,1,1,1
2,1,1,1
3,1,1,1
1,2,1,1
2,2,1,1
3,2,1,1
1,3,1,1
2,3,1,1
3,3,1,1
1,1,2,1
do it until:
3,3,3,3
Am in on the right track?