You could export the array as a JSON (JavaScript Object Notation) string and later decode it again.
You can do this with the functions json_encode
and json_decode
, respectively.
$a = array(
'a' => 1,
'b' => 2,
'c' => array(1,2,3));
file_put_contents('database.txt', json_encode($a));
// encoded: {a:1,b:2,c:[1,2,3]}
// ---
$a = json_decode(file_get_contents('database.txt'), TRUE);
// specify TRUE to parse objects as assoc. arrays ---^
Note, that all this might not be the best idea (I'm a bit worried about the filename you chose – if you want to have a DB, then use a DB! (e.g. sqlite)).