title: PHP Pass variables between PHP files
body: <p>I have a DB connection in a connection.php file.
  With 
  "require_once"
  I include the connection function in a second .php file.
  In this second .php file I call another function from an another .php file and I would like to pass the connecction variable to this function.
  In main file.php i have this:</p>
  
  <pre><code>    require_once("connection.php");
      require_once("print.php");
  
      DBconnection(); //Standard connection to a DB
      print("connection");
  </code></pre>
  
  <p>In connection.php i have:</p>
  
  <pre><code>    function DBconnection()
      {
        $connection= new mysqli($host, $user, $password, $database);
  
        if ($connection-&gt;connect_errno) 
        {
         echo "$connection-&gt;connect_error . ".";
         exit();
        } 
       }
  </code></pre>
  
  <p>Can I pass the connection variable from connection.php to print("connection")?
  print("connection") is a function that print something from the DB choosen from connection.php</p>