Well, it is very easy. Remember, text file access on a server is not fast and should only be used for
smaller arrays. Here is the basic way it is done. Both writing it and reading it back in. Arrays are
stored as text, but, they have indexes and the such. So, to convert them you use the “serialize”
functions which translate them into a format that is writable…
[php]
$serializedData = serialize($array); // Where ‘$array’ is your array name
file_put_contents(‘your_file_name.txt’, $serializedData); // Writes the converted data to the file
// Read the data back in at a later point
$recoveredData = file_get_contents(‘your_file_name.txt’); // Read in the entire file…
$recoveredArray = unserialize($recoveredData); // Convert back to PHP array format
// you can print your array like or do whatever you want with it
print_r($recoveredArray);
[/php]
As you see, this process is so very simple and very easy to use. I did not bother to alter the example
to match your uses. This is just an example on how it is used. Basically, just two lines out and two lines
back in. Very simple. Should work good for you if the array is small.
A couple notes on it’s usage. Remember it is on the server, so the files are protected and are not on
any client’s system. If two users need different data, you will need to have multiple files or just add
another sub-index in the array. (Multidimensional arrays work this way, too.)
Hope that helps…