BWWebDesigns
12-12-2007, 03:57 PM
Need help generating all possible combinations of words from 3 arrays
Lets say i have 3 arrays and each has 10 words in them or how ever many etc
I want to be able to generate an array to be used later on in my script that will contain all possible combinations of the words in the following way
Words will either be taken from the first array only, the first array and the second or the first second and third
so if i had arrays like so
$words1 = array("word1","word2");
$words2 = array("word3","word4");
$words3 = array("word5","word6");
The end outcome would generate an array containing the combinations picking one word combinations from all 3 arrays two word combinations from the first two arrays but only in that order and three word combos from all three in order never mixing the order, the array done by hand would look like this, as these are the combinations generated how i want them.
$combinedwords = array("word1","word2","word3","word4","word5","word6","word1-word3","word1-word4",word2-word3","word2-word4","word1-word3-word5","word1-word4-word5",word1-word3-word6","word1-word4-word6","word2-word3-word5","word2-word4-word5","word2-word3-word6","word2-word4-word6");
Now obviously when theres more words in each array the combinations added to the output array would be greatly increased
Then with the array that is now full of all combinations i can do things with them later in my script but i already have that sorted
Any ideas on how i would do this?
Thanks in a dvance
Lets say i have 3 arrays and each has 10 words in them or how ever many etc
I want to be able to generate an array to be used later on in my script that will contain all possible combinations of the words in the following way
Words will either be taken from the first array only, the first array and the second or the first second and third
so if i had arrays like so
$words1 = array("word1","word2");
$words2 = array("word3","word4");
$words3 = array("word5","word6");
The end outcome would generate an array containing the combinations picking one word combinations from all 3 arrays two word combinations from the first two arrays but only in that order and three word combos from all three in order never mixing the order, the array done by hand would look like this, as these are the combinations generated how i want them.
$combinedwords = array("word1","word2","word3","word4","word5","word6","word1-word3","word1-word4",word2-word3","word2-word4","word1-word3-word5","word1-word4-word5",word1-word3-word6","word1-word4-word6","word2-word3-word5","word2-word4-word5","word2-word3-word6","word2-word4-word6");
Now obviously when theres more words in each array the combinations added to the output array would be greatly increased
Then with the array that is now full of all combinations i can do things with them later in my script but i already have that sorted
Any ideas on how i would do this?
Thanks in a dvance