When you include files in PHP, it acts like the code in the file from which they are included. Present a copy and paste of code from each of your included files directly into your index.php . Here's how PHP works with.
So, in your example, since you set a variable named $name in your front.inc file and then included both front.inc and end.inc in index.php , you can echo $name variable somewhere after include of front.inc inside your index.php . Again, PHP processes your index.php as if the code from the two files you include contains part of the file.
When you put echo inside the included file in a variable that is not defined internally, you will not get the result, because it is processed separately, and then any other included file.
In other words, in order to fulfill the behavior you expect, you will need to define it as global.
Michael Irigoyen Jan 13 2018-11-11T00: 00Z
source share