title: How to change php dotenv (.env) variables dynamically in laravel or php?
body: <p>I want something like this:</p>
  
  <pre><code>env('APP_ENV');
  setenv('APP_ENV', 'testing');
  env('APP_ENV');
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>staging
  testing
  </code></pre>
  
  <p>I find one answer <a href="https://stackoverflow.com/questions/32307426/how-to-change-variables-in-the-env-file-dynamically-in-laravel">How to change variables in the .env file dynamically in Laravel?</a>
  but here .env is saved permanently, I don't want to save permanently.
  How phpunit is doing this ? Because I can put in phpunit.xml this :</p>
  
  <pre><code>...
  &lt;php&gt;
      &lt;env name="APP_ENV" value="testing"/&gt;
  &lt;/php&gt;
  ....
  </code></pre>
  
  <p>And env('APP_ENV') gives me 'testing'...</p>