Doing this as a database is a nice exercise but databases will be faster nearly every time, they'll provide you more flexible query options, and are multi-user safe (except for those database that run based on flat files - as this one does).
Using this as a config file is more likely to be sensible, although i'm sure there are hundreds of config file classes out there http://pear.php.net/Config being the one that has my vote (xml, csv, arrays, define statements - does 'em all).
var_export won't work with some more complicated structures like those containing circular references, particularly references back to the structure they are contained in. For that, you can use serialize and unserialize most of the mechinism is different for those.
Turns out you can do this fairly simply, with only a couple of basic keywords
This part is real easy:
<?php
$foo = Array(); # generally you will want to have named keys
Another easy part, just http://php.net/include it
<?php
include '/home/username/foos.config';# or whereever you want to put it
http://php.net/var_export is actually one of the interesting functions in php. It got some wierd new behaviours in php5, but they only matter for classes, not arrays, so i'll just ignore that...
<?php
# if you pass var_export something
# it will generate the code to create that structure
$foo = Array( spam => eggs );
var_export( Array( foo => bar ) ); # prints: array( foo => bar ) ;
# fairly uninteresting example though
$foo[bar] = 'baz';
$foo[quux] = split( ' ', "this is some text" );
var_export( $foo ); # prints: array( spam => eggs, bar => bax, quux => Array( 'this', 'is', 'some', 'text' ) );
# hrm, that's a little more interesting
var_export also takes a second argument, that when true, causes var_export to return the string, rather than printing it out. (which really should be the default, since printing the result of a function is cleaner). This argument allows you to generate code using var_export...
<?php
$foo = Array('spam', 'eggs');
$code = '<?php $foo = '.var_export( $foo, true ) . '; ?>' ;
# don't be tempted to eval stuff like this, eval is not worth the pain
# $code is something like '<?php $foo = Array(\'spam\', \'eggs\') ; ?>'
If you're on php5, you can use file_put_contents, otherwise, php4 can be done thusly:
<?php
$path = '/home/username/foos.config';
if(
($fh = fopen( $path,'w' ) ) === FALSE
or flock( $fh, LOCK_EX ) === FALSE # we may hang on the flock
or fwrite( $fh, $code ) === FALSE
or fclose( $fh ) === FALSE # fclose also releases the lock
) print "Failed to write";
When we tack all these bits together, we get a script that will preserve our array accross runs (as long as it has permissions to write to the file listed in $path)
<?php
$path = '/home/username/foos.config';
$foo = Array(); # generally you will want to have named keys
@include $path; # silenced because the first time, ever, it will fail
# $foo is updated by the include, to contain the stuff from the file we saved last time
# this is where we make chages to $foo
# based on form submission or whatever pleases you
# now we generate a version of the array, ready to write back to the file
$code = '<?php $foo = '.var_export( $foo, true ) . '; ?>' ;
if(
($fh = fopen( $path,'w' ) ) === FALSE
or flock( $fh, LOCK_EX ) === FALSE # we may hang on the flock
or fwrite( $fh, $code ) === FALSE
or fclose( $fh ) === FALSE # fclose also releases the lock
) print "Failed to write";
else print "Config file written";