note 114238 deleted from function.array-fill by salathe

From: Date: Fri, 21 Nov 2014 15:02:04 +0000
Subject: note 114238 deleted from function.array-fill by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201000@lists.php.net to get a copy of this message
Note Submitter: user at stress dot com ---- $numeri = array(); if ($n >= 2) { $numeriPrimi = array(); //for($y=0; $y <= $n; $y++) $numeri[$y] = 1; $numeri=array_fill(0, ($n+1), 1); $maxChk = (int)sqrt($n); for ($x=2; $x <= $maxChk; $x++) { if (is_np($x, $numeriPrimi)) { $numeriPrimi[] = $x; for ($t = 2; ($x*$t) <= $n; $t++) { unset($numeri[$x*$t]); } } } } unset($numeri[0]); unset($numeri[1]); $numeriPrimi = array_keys($numeri); return $numeriPrimi;

« previous php.notes (#201000) next »