<?php
$number = 100;
$primes = [1,2,3,5,7,11,13,17];
foreach ($primes as $prime) {
if ($number % prime == 0) {
echo "$number is divisible by $prime\n";
} else {
echo "$number is NOT divisible by $prime\n";
}
}
Fatal error: Uncaught Error: Undefined constant "prime" in /in/g3LUj:7
Stack trace:
#0 {main}
thrown in /in/g3LUj on line 7
Process exited with code 255.
Warning: Use of undefined constant prime - assumed 'prime' (this will throw an Error in a future version of PHP) in /in/g3LUj on line 7
Warning: A non-numeric value encountered in /in/g3LUj on line 7
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/g3LUj:7
Stack trace:
#0 {main}
thrown in /in/g3LUj on line 7
Process exited with code 255.
Output for 7.1.0 - 7.1.33
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: A non-numeric value encountered in /in/g3LUj on line 7
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/g3LUj:7
Stack trace:
#0 {main}
thrown in /in/g3LUj on line 7
Process exited with code 255.
Output for 7.0.0 - 7.0.33
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/g3LUj:7
Stack trace:
#0 {main}
thrown in /in/g3LUj on line 7
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 1
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 2
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 3
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 5
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 7
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 11
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 13
Notice: Use of undefined constant prime - assumed 'prime' in /in/g3LUj on line 7
Warning: Division by zero in /in/g3LUj on line 7
100 is divisible by 17