Compared with JSON, Serialize is more suitable for storing PHP variables.
var_export can be used to save the configuration file, and 'include' can be used to load the configuration file information.
This is a simple way to save configuration data programmatically and is easier to read/write. Below is the sample code for the same -
return array( 'var_1'=> 'value_1', 'var_2'=> 'value_2', );
$config = include 'config.php'; $config['var_2']= 'value_3'; file_put_contents('config.php', '<?php return ' . var_export($config, true) . ';');
In addition to the above test.php, you can also use the following The code -
$config = include 'config.php'; $config['var_2']= 'value_3'; file_put_contents('config.php', '$config = ' . var_export($config));
The updated config.php contains the following code -
return array( 'var_1'=> 'value_1', 'var_2'=> 'value_3', );
The above is the detailed content of What's the fastest way to store easily editable configuration data in PHP?. For more information, please follow other related articles on the PHP Chinese website!