Won't claim this is any better/worse:
<?php
/**
* sort characters in string
* @return string
* @param string $word
*/
function sortWord($word)
{
$letters = str_split($word);
sort($letters);
return implode('', $letters);
}
/**
* look for anagram of word in array of words
* @return bool true = found
* @param string $word
* @param array $wordArray
*/
function findWord($word, $wordArray)
{
$word1 = sortWord($word);
foreach($wordArray as $word2)
{
if($word1 == sortWord($word2))
{
return true;
}
}
return false;
}
// Example
$wordList = array('one', 'two', 'three');
var_dump(findWord('noe', $wordList)); // true
var_dump(findWord('xyz', $wordList)); // false
?>