php 更新配置文件

$config_file="路径";
        if(file_exists($config_file)){
            $configs=include $config_file;
        }else {
            $configs=array();
        }
        $configs=array_merge($configs,$data);
        $result = file_put_contents($config_file, "<?php\treturn " . var_export($configs, true) . ";");

  此方法与上一篇http://www.cnblogs.com/qinmei/p/6903333.html最后的结果都一样

  var_export:输出或返回一个变量的字符串表示

     此函数返回关于传递给该函数的变量的结构信息,它和 var_dump() 类似,不同的是其返回的表示是合法的 PHP 代码。

     可以通过将函数的第二个参数设置为 TRUE,从而返回变量的表示。