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

crmpiccoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HeiniHogCommented:
Determines the GCD between them.
0
hieloCommented:
It Determines the greatest common divisor between them. Trace it manually:
<?php
function magic($p, $q) {
  return ($q == 0)
    ? $p
    : magic($q, $p % $q);
}

magic(4,5);
/*
	magic(5,4);
		magic(4,1);
			magic(1,0);
				1


*/
magic(2,4)
/*
	magic(4,2);
		magic(2,0);
			2
*/
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rajkumar_pbCommented:
Answer is :

Determines the greatest common divisor between them

as said by others. you need to trace it manually.
0
crmpiccoAuthor Commented:
excellent!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.