OneCompiler

Prime number sum

159

Example heading with h2 size

Example heading with h3 size

Following is sample php code.

$n = array(1,2,3,4,5,6);

    function prime($n){
        $sum = 0;
        foreach($n as $k => $v) {
            $counter = 0; 
            for($j = 1; $j <= $v; $j++) { 
                if($v % $j == 0)
                    $counter++;

            }

            if($counter == 2) {
                echo $v."<br/>";
                $sum += $v;
            }

        }
        echo "Sum: " . $sum;

    }

    prime($n);