title: php return array from function returns NULL
body: <p>Still just learning PHP so sorry if this is stupid!! I have a function that loops through a mysql adjacency table. I would like to return this as an array. It seems fine, in that if when I return in the function I do print_r($path); where $path is the array inside the function, the array is printed as I want it.</p>
  
  <p>The problem is I cannot see why I cannot access it via </p>
  
  <pre><code>$patharray = functioncalled($vars);
  </code></pre>
  
  <p>I have tried using return $path; and also just <code>print_r</code> in the array, but it keeps returning <code>NULL</code>.</p>
  
  <pre><code>function getParPath($mysqli, $showpar, $path) {
      // Get Parent Path
      $query ="select loc_id, loc_name, loc_parent from locations where loc_id = ? LIMIT 0,1";
      if ($stmt = mysqli_prepare($mysqli, $query)) {
  
          /* pass parameters to query */
          mysqli_stmt_bind_param($stmt, "s", $showpar);
  
          /* run the query on the database */
          mysqli_stmt_execute($stmt);
  
          /* store result */
          mysqli_stmt_store_result($stmt);
  
          /* assign variable for each column to store results in */
          mysqli_stmt_bind_result($stmt, $loc_id, $loc_name, $loc_parent);
  
          /* fetch values */
          while (mysqli_stmt_fetch($stmt)) {
  
              $path[] = $loc_name;
  
              if ($loc_parent !='0'){
                  getParPath($mysqli, $loc_parent, $path);
              }
              if ($loc_parent =='0'){
                  $path = array_reverse($path);
                  return $path; // uncommented per answers below.
                  //print_r($path); //commented out per answers below.
              }
  
          }
      }
  }
  
  $patharray = getParPath($mysqli, $showcld, $path);
  //print_r(getParPath($mysqli, $showcld, $path)); // removed per answers below
  var_dump($patharray); //removed echo per answers below
  exit;
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>Array
  (
      [0] =&gt; BuildingA
      [1] =&gt; FloorA
      [2] =&gt; RoomA
  )
  Array
  (
      [0] =&gt; BuildingA
      [1] =&gt; FloorA
      [2] =&gt; RoomA
  )
  NULL
  </code></pre>
  
  <p>So as you can see from the last line there, the array <code>$patharray</code> I set to the function call is <code>NULL</code>. And that if I try to <code>print_r</code> inside the function, an array is printed, and if I try to <code>print_r</code> the function directly, it returns an array. But not into an object I can use.</p>