I'm trying to loop something which can combine and mix 2 strings.
I want as a result, all possible combinations between characters of the given strings with the scheme "every character of the first string + every character of the second string". Example:
test & name
tame, teme, tese, tesme, teste, tname, tename, tesame, testme, tesname, testame
name & test
namt, nast, nest, namet, namst, ntest, namest, natest, namtest
I'm trying as following:
$str1 = "test";
$str2 = "name";
echo substr($str1,0,1).substr($str2,-3).','.substr($str1,0,2).substr($str2,-2).','.substr($str1,0,1).substr($str2,-4).','.substr($str1,0,3).substr($str2,-2)
.','.substr($str1,0,4).substr($str2,-1).','.substr($str1,0,2).substr($str2,-3).','.substr($str1,0,1).substr($str2,-5).','.substr($str1,0,2).substr($str2,-4)
.','.substr($str1,0,4).substr($str2,-2);
But this is partial and will require a lot to match all combinations. Also it's ugly. And also if the input strings are bigger or smaller, there will be a different amount of combinations.
Do you have any suggestion?