- var_dump: documentation ( source)
- max: documentation ( source)
- min: documentation ( source)
- range: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
<?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));