title: PHP Functions - Notice: Undefined variables problem
body: <p>I created two functions both functions used to work before I turned them into functions and now I get the following errors <code>Notice: Undefined variable: link, url and depth</code> and I was wondering how can I fix this problem so they can work. The problem comes from the last piece of code <code>allCategories($link[0], $url, 0, $depth+1);</code> which I believe stems from the second function.</p>
  
  <p>Function 1</p>
  
  <pre><code>function allCategories($parent = 0, $parent_url = '', $count = 0, $depth = 0){
      catQuery();
      global $link;           
      if($count == 0){
          echo '&lt;ol&gt;';
      } else {
      echo '&lt;ol&gt;';
      }
  
      foreach ($parent as $id =&gt; $cat) {
      if($cat['parent_id'] == '0'){
              $url = $parent_url . $cat['url'];
              $url = str_replace('&amp;#063;cat=', '', $url);
              echo '&lt;li&gt;&lt;a href="http://www.example.com/cat/' . strip_tags($url) . '" title="' . strip_tags($cat['category']) . ' Category Link" class="category-headers"&gt;' . strip_tags($cat['category']) . '&lt;/a&gt;';          
      } else {
              $indent = str_repeat('&amp;nbsp; ', $depth * 1);
              $url = $parent_url . $cat['url'];
              $cat_num = array('&amp;#063;cat=','&amp;#038;sub1=','&amp;#038;sub2='');
              $url = str_replace($cat_num, '/', $url);
              echo '&lt;li&gt;' . $indent . '&lt;a href="http://www.example.com/cat/' . strip_tags($url) . '" title="' . strip_tags($cat['category']) . ' Category Link"&gt;' . strip_tags($cat['category']) . '&lt;/a&gt;';
      }
  
          if(isset($link[$id])) {
              allCategories($link[$id], $url, $count+1, $depth+1);
      }               
              echo '&lt;/li&gt;';
      }       
      echo '&lt;/ol&gt;';
  }
  </code></pre>
  
  <p>Function 2</p>
  
  <pre><code>function catQuery(){
      $cat_dbc = mysqli_query(database(),"SELECT * FROM categories ORDER BY parent_id, category LIKE '%more%', category ASC");
      if (!$cat_dbc) {
              trigger_error(mysqli_error(database()));
      }
  
      $link = array();
      while(list($id, $parent_id, $category, $url, $depth) = mysqli_fetch_array($cat_dbc)){
              $link[$parent_id][$id] = array('parent_id' =&gt; $parent_id, 'category' =&gt; $category, 'url' =&gt; $url, 'depth' =&gt; $depth);
      }
  }
  </code></pre>
  
  <p>Display the desired output.</p>
  
  <pre><code>allCategories($link[0], $url, 0, $depth+1);
  </code></pre>