Serialize is a better option than JSON for storing PHP variables.
I like to use var_export
for saving config file, and using include
for loading config info. This makes it easy to save config data progmatically AND makes the data easy to read/write for a person as well:
config.php:
return array(
'var1'=> 'value1',
'var2'=> 'value2',
);
test.php:
$config = include 'config.php';
$config['var2']= 'value3';
file_put_contents('config.php', '<?php return ' . var_export($config, true) . ';');
Updated config.php now contains the following:
return array(
'var1'=> 'value1',
'var2'=> 'value3',
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…