title: Why can't I pass variables into an included file in PHP?
body: <p>I've had this problem before <a href="https://stackoverflow.com/questions/1601348/passing-php-variables-to-an-included-file">before</a> with no real resolution. It's happening again so I'm hoping you experts can help.</p>
  
  <p>I set a variable on my index.php based on the $_GET array. So I use this code:</p>
  
  <pre><code>$admin = isset($_GET['admin']) ? $_GET['admin'] : "dashboard";
  </code></pre>
  
  <p>Below that, I use a function to include my layout:</p>
  
  <pre><code>include_layout("admin_header.php");
  </code></pre>
  
  <p>which calls this function: </p>
  
  <pre><code>function include_layout($template="") {
      include(SITE_ROOT.DS.'layouts'.DS.$template);
  }
  </code></pre>
  
  <p>So far, so good, everything works. But if I try to echo the $admin variable from within the admin_header.php file, I get nothing. It's as if it's not set. I even test it by using <code>echo $admin;</code> right before I include the header file, and it outputs there, but it's not set from the admin_header.php file's perspective.</p>
  
  <p>Why would this happen? Is it something to do with using a function to include, rather than including it directly? And if so, WHY would that matter?</p>