View Full Version : PHP Help
picch
01-24-2007, 12:59 AM
I've got a question about PHP.
I have 2 files, (File A and File B for now).
Is it possible for me to call a variable or array from File A and use it in File B, or does that create one massive loop?
fischerm
01-24-2007, 12:23 PM
No problems at all. Let's say you have this:
<?php
/**
* This is file 1. It is named file1.php
*/
$myVar = 100;
?>
Then the following separate document:
<?php
/**
* This is file 2. It is named file2.php
*/
require_once("file1.php");
echo $myVar;
?>
The result printed would be 100. The "require_once" is a PHP function that will include all the code from another file. The other file is executed, so if it contained other echo statements, you would see those first. This is a very common technique for storing frequently used functions or data. Hope that helps. PHP.net user manual has a good discussion of require() vs require_once() (http://www.php.net/manual/en/function.require-once.php).
picch
01-26-2007, 03:56 PM
awesome, thanks mark
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.