Hi guys,
I'm working on a little script that generates all combinations of a given input string. My problem is, it's generating the combinations perfectly fine (I checked with an echo), but not inserting them in to an array. Here is my code:
function check($width, $position, $base_string, $charSet)
{
$combinations = array();
for ($i = 0; $i < strlen($charSet); $i++)
{
if ($position < $width - 1)
check($width, $position + 1, $base_string . $charSet[$i], $charSet);
$combinations[] = $base_string . $charSet[$i];
//echo statement here for debugging
}
return $combinations;
}
$word = "hello"
$combinations = array_unique(check(strlen($word), 0, "", $word));
foreach ($combinations as $value)
echo $value;
For some reason, if I add an echo statement to where I marked it in the comment, it prints the values fine. For some reason, it's not inserting them in to the array.