Link to home
Start Free TrialLog in
Avatar of Craig R Morton
Craig R MortonFlag for Australia

asked on

Tricky question in practice PHP Zend Certification exam

I am currently studying towards my Zend PHP certification and have came across this question in my first practice exam:

What does the following function do, when passed two integer values for $p and $q?

The available answers are:
        Loops infinitely
      Switches the values of $p and $q
      Determines if they are both even or odd
      Determines the greatest common divisor between them

Any help appreciated,
Picco
      Calculates the modulus between the two
<?php
function magic($p, $q) {
  return ($q == 0)
    ? $p
    : magic($q, $p % $q);
}
?>

Open in new window

Avatar of HeiniHog
HeiniHog

Determines the GCD between them.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Answer is :

Determines the greatest common divisor between them

as said by others. you need to trace it manually.
Avatar of Craig R Morton

ASKER

excellent!!!