Skip to content
PHP Logo

How can PHP variables be passed between different PHP files using the include() function?

To pass PHP variables between different PHP files using the include() function, you can define the variables in the first PHP file and then include that file in the second PHP file where you want to access those variables. This way, the variables defined in the first file will be available in the second file as well.

php
// File1.php
$var = "Hello, World!";

// File2.php
include 'File1.php';
echo $var; // Output: Hello, World!