I just can’t plunge into the head of how to solve this problem, and after a thorough search on Google without any results, I turn to you with the hope of a solution.
Given the array of samples below:
array(
'Type' => array(
'Toppe',
'Bukser_og_Jeans'
),
'Size' => array(
'Extra_small',
'Small'
),
'Colour' => array(
'Rod'
)
)
(Note: this is just a sample, in a real situation of real life there may be less / more groups and / or elements per group)
How can I end with the following result?
Toppe,Extra_small,Rod
Toppe,Small,Rod
Bukser_og_Jeans,Extra_small,Rod
Bukser_og_Jeans,Small,Rod
This is a product search, and the API supports only one “refinement” value from each group of types, size and color for each request, but my purpose requires a request and aggregation of the results of several API requests.
I think that for this I need some kind of recursive function, but I could not even create code that approximates the expected result.
, Google, - , , , . ", , ", ", , ", ", , " .., , .
, - , , , .
EDIT: , @ikegami, PHP:
$iter = 0;
while (1) {
$num = $iter++;
$pick = array();
foreach ($refinements as $refineGroup => $groupValues) {
$r = $num % count($groupValues);
$num = ($num - $r) / count($groupValues);
$pick[] = $groupValues[$r];
}
if ($num > 0) {
break;
}
print join(', ', $pick)."\n";
}