How can I save and restore an array in PHP?

Aaron

New member
I'm writing a PHP application that requires the ability to take an array, save it in a file, and restore the array later. I've found the var_export function, which converts an array to a String, formatted in such a way that one could re-declare an array with that String.

For example:
<?php
$a = array (1, 2, array ("a", "b", "c"));
$b = var_export($a, true);
?>

$b now contains:
array (
0 => 1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)

and I want to be able to recreate $a by interpreting $b as PHP code. Can this be done?

Thanks for any and all help!
 
Back
Top