一般说来,file_put_contents只能把字符串写入文件,但是有时候需要把数组原样写入到文件,就可以用下面的方法:
<?php
$arr = [1, 234, 3454, 43653];
//将数组写入文件
file_put_contents('test.txt', print_r($arr, true));
//把数组从文件里面读出来
echo "<pre>";
print_r(file_get_contents('test.txt'));
echo "</pre>";
exit;
<?php
$arr = [1, 234, 3454, 43653];
//将数组写入文件
file_put_contents('test.txt', print_r($arr, true));
//把数组从文件里面读出来
echo "<pre>";
print_r(file_get_contents('test.txt'));
echo "</pre>";
exit;
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M