Make your own free website on Tripod.com
Home     My Faqts     Contributors     About     Help    

FAQTS : Computers : Programming : Languages : PHP : Language and Syntax : General

Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

18 of 18 people (100%) answered Yes
Recently 7 of 7 people (100%) answered Yes

How can I create variables that are available in all scripts?

How can I create an array to access from various scripts without passing it using GET or POST?

Jan 22nd, 2000 10:34

Nathan Wallace, Matt Gregory, Dave Martindale


Use the require function:

Create a globals.php3 script, put your array inside:

  <?php
    //script globals.php3
    $myarray[] = "Item1";
    $myarray[] = "Item2";
    $myarray[] = "Item3";
  ?>

then require the script in any scripts which need the array:

  <?php
    //script usearray.php3
    require("globals.php3");
    print($myarray[0]);
  ?>

You can use the auto_prepend_file directive to automatically include the
globals.php3 file before all scripts on a site.

Remember that if you want to use the declared variables inside a
function you will need to define them as being global in that function. 
For example:

    <?php
    function test () {
        global $myarray;
        // do stuff
    }
    ?>



1999-2000 Synop Software