Reputation: 408
1.php:
$x = 10;
2.php:
echo $x;
Both these files are in the same directory. I want to be able to access $x
in 2.php
but I haven't found a good way to do that other than defining another file where i initailize $x
and then include it in both 1.php
and 2.php
. I don't want extra files to deal with in my project.
Edit: FYI, there might be code in 1.php
that I don't want executed in 2.php
so include '1.php'
doesn't work for me
Upvotes: 1
Views: 37
Reputation: 669
You can use include file 1.php in 2.php or require
include '1.php';
Upvotes: 1