title: PHP function not returning string
body: <p>I have constructed a function that takes a filename, and increments a counter in the filename and returns it, however, everything is correct, except the return does not return the filename.</p>
  
  <p>Any help, please?</p>
  
  <p>My code:</p>
  
  <pre><code>$filename = join("", array_reverse($date));
  $filename .= ".xml";
  $dir = "../gigs";
  $file = $dir."/".$filename;
  
  function getNewFileName($filename, $dir) {
  if (is_file("$dir/$filename")) {
      if (strpos($filename, "_") === false) {
          $filename = str_replace(".xml","_1.xml",$filename);
          getNewFileName($filename, $dir);
      }
      else {
              $pos = strpos($filename, "_");
              $counter = (int)substr($filename, $pos+1,1);
              $counter++;
              $filename = substr($filename,0, $pos)."_".$counter.".xml";
              getNewFileName($filename, $dir);
          }
      } else {
                  // echoing HERE shows that the string is manipulated correctly
          return (string)$filename; // but returning here is not working
      }
  }
  
  echo getNewFileName($filename, $dir); // &lt;- this last line prints nothing out
  </code></pre>
  
  <p>Thanks in advance.</p>