I'm fairly new to PHP and am having trouble with variables. When I put everything in one PHP file, it works but my question is should this work? I am under the impression that when you include a file then the variables are also included. Assuming that is true, when connecting to a DB, is it good practice to connect in a separate PHP file then include that into pages where you need to use the DB?
page1.php
<?php
$test = "true";
?>
page2.php
<?php
$test = "false";
?>
home.php
<?php
include 'page1.php';
include 'page2.php';
echo $test;
?>
Expected output false but I am getting true.
trueas the output.