Home >Backend Development >PHP Tutorial >How Can a Recursive Function Generate All Combinations from Multiple Arrays?
This question seeks a solution to generate all possible combinations of elements from multiple arrays of varying sizes.
The provided solution utilizes a recursive function combinations that takes an array of arrays ($arrays) as input. It recurses through the arrays recursively, combining elements from each array to form all possible combinations.
The recursion proceeds as follows:
An example usage of the function is provided to demonstrate its application to generate combinations from three arrays (arrayA, arrayB, and arrayC). The resulting combinations are printed in the desired format.
This recursive solution efficiently generates all possible combinations of elements from multiple arrays, irrespective of their number or size.
The above is the detailed content of How Can a Recursive Function Generate All Combinations from Multiple Arrays?. For more information, please follow other related articles on the PHP Chinese website!