This is a simple solution to your problem. I concatenate each row repeatedly to the remaining in the array.
$string = "this is a string";
$strings = explode(' ', $string);
print_r(concat($strings, ""));
function concat(array $array, $base_string) {
$results = array();
$count = count($array);
$b = 0;
foreach ($array as $key => $elem){
$new_string = $base_string . " " . $elem;
$results[] = $new_string;
$new_array = $array;
unset($new_array[$key]);
$results = array_merge($results, concat ($new_array, $new_string));
}
return $results;
}
source
share