3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$values = [ 16, 32, 48]; $values = range(16, 1000000, 2); function getCmmdc($values) { $num_values = count($values); $x = current($values); $y = next($values); for ($i = 1; $i < $num_values; $i ++) { $a = max($x, $y); $b = min($x, $y); $c= 1; do { $c = $a % $b; $gcf = $b; $a = $b; $b = $c; } while ($c != 0); $x = $gcf; $y = next($values); } //suma tuturor divizilorilor $sum = 0; for($i = 1; $i <= $gcf; $i ++){ $temp = $gcf % $i; if($temp == 0){ $sum += $i; } } return array($gcf, $sum); } var_dump(getCmmdc($values));
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.1, 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(2) { [0]=> int(2) [1]=> int(3) }
Output for 8.1.2 - 8.1.27
Fatal error: Out of memory (allocated 18878464) (tried to allocate 16777224 bytes) in /in/BBHMq on line 9 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /in/BBHMq on line 3
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /in/BBHMq on line 3
Process exited with code 255.
Output for 5.2.1 - 5.2.2
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 24 bytes) in /in/BBHMq on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Warning: Wrong parameter count for range() in /in/BBHMq on line 3 Warning: current(): Passed variable is not an array or object in /in/BBHMq on line 8 Warning: next(): Passed variable is not an array or object in /in/BBHMq on line 9 Notice: Undefined variable: gcf in /in/BBHMq on line 27 Notice: Undefined variable: gcf in /in/BBHMq on line 34 array(2) { [0]=> NULL [1]=> int(0) }
Output for 4.3.0 - 4.3.1
Warning: Wrong parameter count for range() in /in/BBHMq on line 3 Warning: current() [http://www.php.net/function.current]: Passed variable is not an array or object in /in/BBHMq on line 8 Warning: next() [http://www.php.net/function.next]: Passed variable is not an array or object in /in/BBHMq on line 9 Notice: Undefined variable: gcf in /in/BBHMq on line 27 Notice: Undefined variable: gcf in /in/BBHMq on line 34 array(2) { [0]=> NULL [1]=> int(0) }

preferences:
227.29 ms | 402 KiB | 329 Q