$textone = "pate"; //$_GET
$texttwo = "tape";
$texttre = "tapp";
if ($textone ??? $texttwo) {
echo "The two strings contain the same letters";
}
if ($textone ??? $texttre) {
echo "The two strings NOT contain the same letters";
}
What if statement am I looking for?
I suppose a solution could be to, considering the two following variables :
1. First, split the strings, to get two arrays of letters :
Note that, as pointed out by @Mike in his comment, instead of using
preg_split()like I first did, for such a situation, one would be better off usingstr_split():2. Then, sort those array, so the letters are in alphabetical order :
3. After that, implode the arrays, to create words where all letters are in alphabetical order :
4. And, finally, compare those two words :
Turning this idea into a comparison function would give you the following portion of code :
And calling that function on your two words :
Would get you the following result :