3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function generatePrimesA($n) { $primes = [2]; for ($i = 3; $i < $n; $i += 2) { foreach ($primes as $prime) { if ($i % $prime == 0) { continue 2; } } $primes[] = $i; } return $primes; } function generatePrimesB($n) { $primes = [2]; $lastPrime = 2; for ($i = 3; $i < $n; $i += $lastPrime) { foreach ($primes as $prime) { if ($i % $prime == 0) { continue 2; } } $primes[] = $i; $lastPrime = $i; } return $primes; } var_dump(count(generatePrimesA(1000))); var_dump(count(generatePrimesB(1000))); var_dump(array_diff(generatePrimesA(1000), generatePrimesB(1000)));
Output for 5.4.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
int(168) int(2) array(166) { [2]=> int(5) [3]=> int(7) [4]=> int(11) [5]=> int(13) [6]=> int(17) [7]=> int(19) [8]=> int(23) [9]=> int(29) [10]=> int(31) [11]=> int(37) [12]=> int(41) [13]=> int(43) [14]=> int(47) [15]=> int(53) [16]=> int(59) [17]=> int(61) [18]=> int(67) [19]=> int(71) [20]=> int(73) [21]=> int(79) [22]=> int(83) [23]=> int(89) [24]=> int(97) [25]=> int(101) [26]=> int(103) [27]=> int(107) [28]=> int(109) [29]=> int(113) [30]=> int(127) [31]=> int(131) [32]=> int(137) [33]=> int(139) [34]=> int(149) [35]=> int(151) [36]=> int(157) [37]=> int(163) [38]=> int(167) [39]=> int(173) [40]=> int(179) [41]=> int(181) [42]=> int(191) [43]=> int(193) [44]=> int(197) [45]=> int(199) [46]=> int(211) [47]=> int(223) [48]=> int(227) [49]=> int(229) [50]=> int(233) [51]=> int(239) [52]=> int(241) [53]=> int(251) [54]=> int(257) [55]=> int(263) [56]=> int(269) [57]=> int(271) [58]=> int(277) [59]=> int(281) [60]=> int(283) [61]=> int(293) [62]=> int(307) [63]=> int(311) [64]=> int(313) [65]=> int(317) [66]=> int(331) [67]=> int(337) [68]=> int(347) [69]=> int(349) [70]=> int(353) [71]=> int(359) [72]=> int(367) [73]=> int(373) [74]=> int(379) [75]=> int(383) [76]=> int(389) [77]=> int(397) [78]=> int(401) [79]=> int(409) [80]=> int(419) [81]=> int(421) [82]=> int(431) [83]=> int(433) [84]=> int(439) [85]=> int(443) [86]=> int(449) [87]=> int(457) [88]=> int(461) [89]=> int(463) [90]=> int(467) [91]=> int(479) [92]=> int(487) [93]=> int(491) [94]=> int(499) [95]=> int(503) [96]=> int(509) [97]=> int(521) [98]=> int(523) [99]=> int(541) [100]=> int(547) [101]=> int(557) [102]=> int(563) [103]=> int(569) [104]=> int(571) [105]=> int(577) [106]=> int(587) [107]=> int(593) [108]=> int(599) [109]=> int(601) [110]=> int(607) [111]=> int(613) [112]=> int(617) [113]=> int(619) [114]=> int(631) [115]=> int(641) [116]=> int(643) [117]=> int(647) [118]=> int(653) [119]=> int(659) [120]=> int(661) [121]=> int(673) [122]=> int(677) [123]=> int(683) [124]=> int(691) [125]=> int(701) [126]=> int(709) [127]=> int(719) [128]=> int(727) [129]=> int(733) [130]=> int(739) [131]=> int(743) [132]=> int(751) [133]=> int(757) [134]=> int(761) [135]=> int(769) [136]=> int(773) [137]=> int(787) [138]=> int(797) [139]=> int(809) [140]=> int(811) [141]=> int(821) [142]=> int(823) [143]=> int(827) [144]=> int(829) [145]=> int(839) [146]=> int(853) [147]=> int(857) [148]=> int(859) [149]=> int(863) [150]=> int(877) [151]=> int(881) [152]=> int(883) [153]=> int(887) [154]=> int(907) [155]=> int(911) [156]=> int(919) [157]=> int(929) [158]=> int(937) [159]=> int(941) [160]=> int(947) [161]=> int(953) [162]=> int(967) [163]=> int(971) [164]=> int(977) [165]=> int(983) [166]=> int(991) [167]=> int(997) }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/61J9Z on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/61J9Z on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/61J9Z on line 4
Process exited with code 255.