Hi, I found the code here, it's excately what i am looking for, ie8 give this error "Notice: Undefined offset: 49 in.." which is this line "if ($num_of_chars[49]==$required)", i'm a newbie, i don't know how to overcome this error, so can someone please help me out?
thanks,
thanks,
Code:
$string = "one two three";
$word_array = explode(" ",$string);
for ($i=count($word_array); $i>=1; $i--)
{
$word = $i == 1 ? " word" : " words";
echo "Strings containing combination of ".$i.$word.":<br>";
$flags = array();
$combination_flags = get_combination_flags(count($word_array), $i);
$flags_groups = explode(",",$combination_flags);
foreach ($flags_groups as $val)
{
$temp = chunk_split($val,1,".");
array_push($flags, explode(".", substr($temp,0,(strlen($temp)-1))));
}
for ($j=0; $j<count($flags); $j++)
{
$new_string = "";
for ($k=0; $k<count($word_array); $k++)
$new_string .= $flags[$j][$k] ? " ".$word_array[$k] : "";
trim ($new_string);
echo $new_string."<br>";
}
echo "<br>";
}
function get_combination_flags($total, $required)
{
$flag_array = array();
$bin = "";
for ($i=0; $i<$total; $i++)
$bin .= "1";
$dec = bindec($bin);
for ($i=0; $i<=$dec; $i++)
{
$num_of_chars = count_chars(decbin($i), 1);
[B][U]if ($num_of_chars[49]==$required)[/U][/B]
{
$temp = decbin($i);
$length = strlen($temp);
$pre = "";
if ($length<$total) for ($j=$length; $j<$total; $j++) $pre .= "0";
$temp = $pre.$temp;
array_push($flag_array,$temp);
}
}
return implode(",",$flag_array);
}
?>
Comment