Assuming that $arr1 is an array, and $haystack is a string, when I call this method into my class, it doesn’t respond properly.
$arr1 = [];
// This is a function that generate every string combinations from needle ('dio', 'iod', 'odi', etc)
function permute();
class checkAnagram {
public function anagram(string $needle, string $haystack, &$arr1): bool {
if ((strlen($needle) > 1024 || strlen($haystack) > 1024) || strlen($needle) > strlen($haystack)) {
return 0;
}
$needle = strtolower($needle);
$haystack = strtolower($haystack);
$str = strtolower($needle);
permute($str, 0, strlen($str), $arr1);
for ($i = 0; $i < count($arr1); $i++) {
if (stripos($haystack, $arr1[$i]) !== false) {
return true;
}
}
return false;
}
}
$amara = new checkAnagram();
echo $amara->anagram('Dio', 'Aasadio', $arr1);
It ends to echo nothing, false neither.
>Solution :
Your arguments are reversed in stripos. $haystack should come first. Echoing true will return 1, false will return nothing, which is why you aren’t seeing anything.