PHP - check if number is prime
<p>I'm trying to create a function which checks whether the number is prime or not. BUT I want this function to echo to the user 'prime' or 'NOT prime' - and that's where my problem starts. 
Let me show you my code:</p>

<pre><code>class IsPrime
{       
    function check($num)
    {
        for ($i = 2; $i &lt; $num; $i++)
        {
            if ($num % $i == 0) 
            {
                echo 'NOT prime';
                break;
            }               
        }
        echo 'Prime';           
    }       
}

$x = new IsPrime();
$x-&gt;check(4);
</code></pre>

<p>The problem is that when I put any prime number - it works correctly, but when I put any not prime number - it also echos second echo, sth like this: <code>'NOT prime prime'</code>.</p>

<p>How can I make it echo only the right answer ?</p>