I want to define PHP variables in one script, and extract them in a sencond script later.
I think the best way to achieve this, is to use serialize and unserialize.
$all_vars = serialize(get_defined_vars());
file_put_contents('vars.txt', $all_vars);
unset($all_vars);
$all_vars = unserialize(file_get_contents('vars.txt', true));
foreach ($all_vars as $key => $value) {
$$key = $value;
}
unset($all_vars);
$all_vars = serialize(get_defined_vars());
file_put_contents('vars2.txt', $all_vars);
I would exspect that I have 2 textfiles (vars.txt and vars2.txt) with the exact same content, but they are slightly different.
For example:
vars.txt:
"value_a";r:537;s:10:"key_a";i:1090986352011110587;s:7:"counter"
vars2.txt:
"value_a";a:1:{i:1090986352011110587;r:538;}s:10:"key_a";i:1090986352011110587;s:7:"counter"