title: Writing a PHP file to another file, in another directory, with different values dependant on variables
body: <p>I'm fairly new to PHP, so I'm sorry if this is a dumb question. </p>
  
  <p>I'm trying to create something to write a PHP file to another file in another directory. The idea being that all the generated directories have to include a file which is run via cron, however I can't simply just copy the file because part of the file is dependant on a variable that exists when the directory gets created, but isn't always going to be there.</p>
  
  <p>It would be the same scenario as writing the following to a file (obviously this is an example):</p>
  
  <pre><code>&lt;?php
      $test = mysql_query("SELECT * FROM table WHEN memberID='$groupID'");
  ?&gt;
  </code></pre>
  
  <p>How would I get the variable <code>$groupID</code> from the file carrying out the <code>fopen('','w')</code> function which is writing the new PHP file? Can anyone give an example of writing the above to a file? </p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong> I've accepted the answer to the original question, however the answer from @MichaelBerkowski is an efficient alternative to consider.</p>