Decoding anagram with recursive function doesn't give expected output
<p>So I'm trying to decode an anagram into words from my dictionary file. But my recursive function isn't behaving like I'm expecting.</p>

<p>The thoughts about the code is to eliminate letters as they are used on words and output me the string it came up with.</p>

<pre><code>&lt;?php

function anagram($string, $wordlist)
{
    if(empty($string))
        return;

    foreach($wordlist as $line)
    {
        $line = $org = trim($line);
        $line = str_split($line);
        sort($line);

        foreach($line as $key =&gt; $value)
        {
            if($value != $string[$key])
            {
                continue 2;
            }
        }

    echo $org . anagram(array_slice($string, count($line)), $wordlist); 
    }

    echo PHP_EOL;

}


$string = "iamaweakishspeller";
$string = str_split($string);
sort($string);

$file = file('wordlist');

anagram($string, $file);
</code></pre>

<p>This is my result for now, it looks awful, but I'm having some issues with the code - it's going into an indefinite loop with the same roughly 200 words from the word list.</p>

<p>Can someone take an extra peak at this?</p>