📜  将数组打印到文件 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:23.088000             🧑  作者: Mango

代码示例1
//Either var_export or set print_r to return the output instead of printing it.
$b = array (
    'm' => 'monkey', 
    'foo' => 'bar', 
    'x' => array ('x', 'y', 'z'));

$results = print_r($b, true); // $results now contains output from print_r
//You can then save $results with file_put_contents. Or return it directly when writing to file:

file_put_contents('filename.txt', print_r($b, true));