php - How to build recursive function to list all combinations of a multi-level array? -
I have an array that contains elements of any number in each element including an ID and an array called "Options" (With any number of elements). Array (3, 5)), array ('id' ===================================== ================ (2, 4, 8, 9)), array ('id' => 20, 'options' => array (2, 6, 7)), // ... any number of elements);
I want to create another array on the basis of this one. Each key ID field is an 'option' array value, and the value is an array of the next element, and then the next, and so on. Basically I should give each combination of the arrays (like a tree) given above, in order that the array was defined:
$ new = array ('10 -3 '= & Gt; array ('15 -2' => array ('20 -2 ', '20 -6', '20 -7 '), '15 -4' => array ('20 -2 ', '20 -6', '20 -7 '), '15 -8' = & gt; array ('20 -2 ', '20 -6', '20 -7 '), '15 - 9 '= & gt; array ('20 -2', '20 -6 ', '20 -7')), '10 -5 '=> array ('15 -2' => array ( '20 -2 ', '20 -6', '20 -7 '), '15 -4' => array ('20 -2 ', '20 -6', '20 -7 '),' 15 -8' = & gt; array ('20 -2 ', '20 -6', '20 -7 '), '15 -9' => array ('20 -2 ', '20 -6 ', '20 -7')));
Because any elements can be included in the array, I'm assuming that I will need to include some types of recursive functions. I do not have much experience in repetition, so this is a daunting task for me.
Should I ask this indicator to start in the creation of this recursive function?
How to do this? Sure there is a bug, but its going in the right direction ....
Function prospects ($ input) {$ output = array (); $ Current = array_shift ($ input); Foreign currency ($ current is $ current = & gt; $ value) {If empty ($ input) {$ output is $] = $. ' $ Value; } And {$ Output [$ key. '-'. $ Value] = Prospects ($ input); }} Returns $ output; }
Comments
Post a Comment