title: How to Create Global Variable Dynamically in PHP
body: <p>I need to create some global variable in PHP through function dynamically to be used out of function</p>
  
  <p>I tried</p>
  
  <pre><code>&lt;?php
  function setthis(newglobal){
    global $_.newglobal._1;
    $_.newglobal._1 = "pampam";
  }
  setthis();
  
   echo $_newglobal_1;
  ?&gt;
  </code></pre>
  
  <p>and I am getting this error</p>
  
  <p>Line : 2,   Error type : 4</p>
  
  <blockquote>
    <p>Message : syntax error, unexpected ')', expecting '&amp;' or variable
    (T_VARIABLE)</p>
  </blockquote>
  
  <p>I also tried wrap them in quoted the variable like</p>
  
  <pre><code>&lt;?php
  function setthis(newglobal){
    global $_.'newglobal'._1;
    $_newglobal_1 = "pampam";
  }
  setthis();
  
   echo $_newglobal_1;
  ?&gt;
  </code></pre>
  
  <p>an I am getting error Message</p>
  
  <blockquote>
    <p>: syntax error, unexpected ')', expecting '&amp;' or variable
    (T_VARIABLE)</p>
  </blockquote>
  
  <p>can you please let me know if this is doable in PHP? or what I am doing wrong?</p>
  
  <blockquote>
    <p>Update</p>
  </blockquote>
  
  <pre><code>&lt;?php
  function setthis($name){
      $GLOBALS[$name];
      $name = "pampam";
  }
  setthis();
  echo $name;
  ?&gt;
  </code></pre>