Alternative to global array variable?

I’m trying to structure my first application in separate files as follows (the logic being that manipulation of an array in memory will be quicker than continually reading from file):

index.php - declares an array, and reads a text file (perhaps 150,000 lines of text ~ 3MB) into that array using a function in the included file functions.php. User clicks a link to continue to list.php

list.php - needs to manipulate the array declared in index.php, includes ‘functions.php’.

show.php - needs to manipulate the array declared in index.php, includes ‘functions.php’.

functions.php - contains functions accessible to all files.

I have no problem accessing the global array in functions php using the ‘global’ keyword but how can I access it in list.php and show.php which aren’t ‘included’ in index?

I guess I’m asking how can list.php and show.php share the same scope as index.php without being ‘included’ (and I suspect the answer is they can’t!) or is there a way to emulate a pointer to this global array?

TIA

Paul

Are you saving the array to session?

No, I haven’t read up on that yet… is that the way to go?

Paul

Right, I think I understand the essential features of sessions now but if I read the file into an array and save it like so in index.php:

$_SESSION[‘myArray’] = $arrayFromFile

…doesn’t that mean that when I access this session variable from another program file that it will be read back in from a file on the server? I’m guessing that session variables would have to be stored in a file on the server rather than in memory, which seems to negate any advantage this might offer!

Paul

Sponsor our Newsletter | Privacy Policy | Terms of Service