title: Function returns null (returned value is not null) in PHP
body: <p>I have been scratching my head over a function for a while now and was wondering if anyone could see what I'm doing wrong? I'm trying to return a value from a function but it is null, even though I know that the value I return isn't. Here's my function:</p>
  
  <pre><code>if (!function_exists('findTopLevel')){
      function findTopLevel($id){
          $DatabaseID = $id;
  
          echo json_encode($DatabaseID); //correct
          $parentID = $_SESSION['items'][$DatabaseID]['ParentID'];
          echo json_encode($parentID); //correct
  
          if($parentID == "top"){
              echo json_encode($DatabaseID); //correct
              return $DatabaseID; //returns null
          }
  
          else if($parentID !== "top"){
              ini_set('memory_limit', '-1'); 
              findTopLevel($parentID);
          }
      }
  }
  </code></pre>
  
  <p>I call it here:</p>
  
  <pre><code>if(!strpos($HiddenPositionArray, $DatabaseID)){
  
          $topLevel = findTopLevel($DatabaseID);
          echo json_encode($topLevel); //says: null
      }
  </code></pre>
  
  <p>(I will not echo all these stuff when I know it works.)</p>
  
  <p>What's wrong?</p>