3v4l.org

run code in 300+ PHP versions simultaneously
<?php function perfect($n) { if ($n < 1) { echo "Number has to be Positive."; return false; } for($i = 1; $i <= $n; $i++) { if ($n % $i == 0) { $factors[] = $i; } else { echo "$i is not a factor" . PHP_EOL; } } return ($n == array_sum($factors) / 2) ? true : false; } perfect(42); ?>
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.9, 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
4 is not a factor 5 is not a factor 8 is not a factor 9 is not a factor 10 is not a factor 11 is not a factor 12 is not a factor 13 is not a factor 15 is not a factor 16 is not a factor 17 is not a factor 18 is not a factor 19 is not a factor 20 is not a factor 22 is not a factor 23 is not a factor 24 is not a factor 25 is not a factor 26 is not a factor 27 is not a factor 28 is not a factor 29 is not a factor 30 is not a factor 31 is not a factor 32 is not a factor 33 is not a factor 34 is not a factor 35 is not a factor 36 is not a factor 37 is not a factor 38 is not a factor 39 is not a factor 40 is not a factor 41 is not a factor
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 4 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 5 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 8 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 9 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 10 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 11 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 12 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 13 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 15 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 16 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 17 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 18 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 19 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 20 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 22 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 23 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 24 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 25 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 26 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 27 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 28 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 29 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 30 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 31 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 32 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 33 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 34 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 35 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 36 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 37 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 38 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 39 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 40 is not a factorPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/fNTQG on line 12 41 is not a factorPHP_EOL

preferences:
242.6 ms | 409 KiB | 354 Q