title: php function returns null instead of string
body: <p>I have an array with all categories stored in it:</p>
  
  <pre><code>$allCatArray = array(
                        ['departments/outdoor/123123/'] =&gt; stdClass Object
                            (
                                [i] =&gt; 1
                                [id] =&gt; 'departments/outdoor/123123/'
                                [pid] =&gt; 'departments/outdoor/'
                                [name] =&gt; 'Child Category Name'
                            )
                        ['departments/outdoor/'] =&gt; stdClass Object
                            (
                               [i] =&gt; 1
                               [id] =&gt; 'departments/outdoor/'
                               [pid] =&gt; '0'
                               [name] =&gt; 'Main Category Name'
                            )
  </code></pre>
  
  <p>I need detect the highest category in hierarchy when i have id of lower category in hierarchy. So I have this function:</p>
  
  <pre><code>function findMainCategoryFromAllCatArray($initial_category, $allCatArray) {
    $pid = trim($allCatArray[$initial_category]-&gt;pid);
    if($pid != "0") {
      findMainCategoryFromAllCatArray($pid, $allCatArray);
    }
    elseif($pid == "0") {
      var_dump($allCatArray[$initial_category]-&gt;name); // this var dump returns normal value
      return $allCatArray[$initial_category]-&gt;name;
    }
    else {
      return false;
    }
  }
  </code></pre>
  
  <p>I'm getting trouble when trying to use this function:</p>
  
  <pre><code>$category_name = findMainCategoryFromAllCatArray('departments/outdoor/123123/', $allCatArray);
  var_dump($category_name); // returns NULL instead of "Main Category Name"
  </code></pre>
  
  <p>Any ideas?</p>