PHP Basics Learning Mode

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

<?php
function magic($p, $q)
{  
     return ($q == 0)    ? $p    : magic($q, $p % $q);
}
?>