← All examples

GCD (Euclid)

PHP Algorithms

while loop

Flowchart (ISO 5807)

YesNoStartInput a, bb != 0t = bb = a % ba = tReturn aEndFigure 1 — gcd

Source code

function gcd($a, $b) {
    while ($b != 0) {
        $t = $b;
        $b = $a % $b;
        $a = $t;
    }
    return $a;
}