How to generate multiple string base on given string with space separator. Ex.: I have one string like
Ex.:1 'This is string'
will output following strings: 'This is', 'This string', 'is string'
$arrStrSplit = explode($splitBy, $strInfo);
for($outer = 0; $outer < count($arrStrSplit); $outer++)
{
for($inner = $outer+1; $inner < count($arrStrSplit); $inner++)
{
array_push($arrStrSplitPair, $arrStrSplit[$outer].' '.$arrStrSplit[$inner]);
}
}
What if have multiple word string more than 3+
Ex.2: 'This is new string'
Output:
'This is', 'This new', 'This string', 'is new', 'is string', 'new string',
'This is new', 'This is string', 'This new string', 'is new string'
so on : Input string have any no. of words. From 2 to 15-20 etc...
i.e. No. of word string from 2 TO (No. of word of given string - 1)
After many updates...
http://php.net/manual/en/function.shuffle.php#88408
$string = 'This is new string';
$array = explode(' ', $string);
function powerSet($in, $minLength = 1) {
$count = count($in);
$members = pow(2,$count);
$return = array();
for ($i = 0; $i < $members; $i++) {
$b = sprintf("%0".$count."b",$i);
$out = array();
for ($j = 0; $j < $count; $j++) {
if ($b{$j} == '1') $out[] = $in[$j];
}
if (count($out) >= $minLength) {
$return[] = $out;
}
}
return $return;
}
$sets = powerSet($array, 1);
That's all I think! Best regards!