解决方案 »

  1.   

    $s =<<< TXT
    写一个数组
    以字符串的形式
    保存在一个txt文件里面
     可以
    通过修改TXT的方式
    增加数组内容
    TXT;
    file_put_contents('data.txt', $s); //准备工作结束$ar = file('data.txt', FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
    print_r($ar);
      

  2.   


    $arr=array(1,2,3,4,5);
    $str=serialize($arr);
    file_put_contents('test.txt',$str);
      

  3.   

    写入
    $arr = array(1,2,3,4,5);
    $str = json_encode($arr);
    file_put_contents('test.txt', $str, true);读取并修改
    $str = file_get_contents('test.txt');
    $arr = json_decode($str, true);
    array_push($arr, 6);
    $str = json_encode($arr);
    file_put_contents('test.txt', $str, true);
      

  4.   

    $str = var_export($array, true);
    file_put_contents('file.php', $str);include('file.php');