Serialize tốt hơn JSON để lưu biến PHP.
var_export có thể dùng lưu file config, và 'include' để nạp thông tin config.
Đây là cách dễ dàng lưu config data programmatically và dễ đọc/viết. Mã mẫu:
config.php
return array(
'var_1' => 'value_1',
'var_2' => 'value_2',
);
test.php
$config = include 'config.php';
$config['var_2'] = 'value_3';
file_put_contents('config.php', '
Thay cho test.php trên, mã dưới cũng dùng được:
$config = include 'config.php';
$config['var_2'] = 'value_3';
file_put_contents('config.php', '$config = ' . var_export($config));
File config.php cập nhật chứa mã sau:
return array(
'var_1' => 'value_1',
'var_2' => 'value_3',
);