So, I am trying to get a list of every possible combination of a set of words.
With the input text "1, 2" and the values being ("1" => "a", "b", "c") and ("2" => "d", "e"), I would get something like:
a, d
b, d
c, d
a, e
b, e
c, e
With the code I have right now, I only get:
a, d
b, d
c, d
How can I get around this?
Code:
foreach ($words as $word)
{
for ($i = 0; $i < count($array); $i++) //For every value
{
$key = array_keys($array[$i])[0];
if ($word === $key)
{
$syn = explode("|", $array[$i][$key]); //Get all synonyms
foreach ($syn as $s) //For each synonym within
{
$potential[] = implode(" ", str_replace($key, $s, $words));
}
}
}
}
The procedure is for every word in the input text, we want to go through our entire array of values. In there, we have other arrays ("original" => "synonyms"). From there, we loop through every synonym and add it to a list of potential combinations.