Compare two strings and returns true if both strings are anagram, false otherwise.

 

title tags
isAnagram
string,beginner
  • Use count_chars() to compare $string1 and $string2.
function isAnagram($string1, $string2)
{
  return count_chars($string1, 1) === count_chars($string2, 1);
}
isAnagram('act', 'cat'); // true

License: CC-0