3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class AreAnagrams { public static function areStringsAnagrams($a, $b) { $a_arr = str_split(strtolower($a)); $b_arr = str_split(strtolower($b)); $az = range('a', 'z'); foreach ($a_arr as $char) { if (!isset($comp_arr[$char])) { $comp_arr[$char] = 0; } if (in_array($char, $az)) { $comp_arr[$char]++; } } foreach ($b_arr as $b_char) { if (!isset($comp_arr[$b_char])) { return FALSE; } if (in_array($char, $az)) { $comp_arr[$b_char]--; } } if (array_sum($comp_arr) !== 0) { return FALSE; } return TRUE; } } echo AreAnagrams::areStringsAnagrams('neural', 'unreal') ? 'True' : 'False'; echo AreAnagrams::areStringsAnagrams('sample', 'Maples') ? 'True' : 'False'; echo AreAnagrams::areStringsAnagrams('better', 'brttee') ? 'True' : 'False'; echo AreAnagrams::areStringsAnagrams('letter to editor', 'Retorted Toilet') ? 'True' : 'False'; echo AreAnagrams::areStringsAnagrams('letter to editor', 'Delete Riot Trot') ? 'True' : 'False'; echo AreAnagrams::areStringsAnagrams('letter to editor', 'Loitered Totter') ? 'True' : 'False';
based on skvpY
Output for 5.5.0 - 7.2.0
TrueTrueTrueFalseFalseFalse