title: counting the number of times a recursive function is called
body: <p>I need to know how many times a recursive function is called within the function. This is my function:</p>
  
  <pre><code>function structure($x) {
  $qry = mysql_query("SELECT `parent_id` FROM `categories` WHERE `categories_id`=$x");
  $result = mysql_fetch_assoc($qry);
  $cat = $result['parent_id'];
  if($cat !=0) {
      structure($cat);
  }
  echo $cat.' &gt;';
  }
  </code></pre>
  
  <p>I have tried adding a counter, e.g. $i=0, then $i++, but it will of course revert back to the $i=0 every time the function is called. I have tried adding arrays, and counting the arrays, but of course it has to set a new array, $i=array(), every time the function is called. </p>
  
  <p>The one way I can think might work is if I set the array or counter outside of the function, but I don't know if its possible to call a variable in a function that is outside the function.</p>
  
  <p>Any ideas on how to call a variable outside a function or even a better way to count the times the function is called?</p>