可以通过将函数的第二个参数设置为 TRUE,从而返回变量的表示。
$fp = fopen('./file.txt', 'a+b'); fwrite($fp, var_export($content, true)); fclose($fp);
注意 var_export() 的第二个参数需要设置为 true 才表示取得返回值。要不然是直接输出
另外,如果你的 $content 只是一个数组,而不包含其他的内容的话
你也可以用 print_r()
同样的,print_r() 的第二个参数也要设置为 true
$fp = fopen('./file.txt', 'a+b');fwrite($fp, print_r($content,
true));fclose($fp);