0

我创建了一个生成数组的脚本。需要存储此数组,以便如果用户想要导出其内容(例如 print ),它可能是可能的。
这是我的数组 ($doc)

Array  
     (  
    [0] => Array  
    (  
        [0] => ------  
        [1] => ---Start----  
        [2] => -------  
        [3] => Generated on Saturday, 3rd, August 2013  
    )

[1] => Array
    (
        [0] => ------
        [1] => -------
        [2] => -------
        [3] => -----------------------
    )

[2] => Array
    (
        [0] => Tid
        [1] => Policy
        [2] => Budget
        [3] => User
        [4] => Capturetime
        [5] => Country
    )

[3] => Array
    (
        [0] => 1
        [1] => ask
        [2] => das
        [3] => carol
        [4] => 2013-07-09
        [5] => Ethiopia
    )

[4] => Array
    (
        [0] => 2
        [1] => das
        [2] => adsasd
        [3] => ck
        [4] => 2007-07-13
        [5] => Slovakia
    )

[5] => Array
    (
        [0] =>  
        [1] =>  
        [2] =>  
        [3] =>  
    )

[6] => Array
    (
        [0] => ------
        [1] => ---End----
        [2] => -------
    )

)

现在我将数组保存到一个文件中:
file_put_contents('array.txt', print_r($printdoc, true));
然后我想将 array.txt 的内容回调到数组 $printdoc 并将其用作数组。 $printdoc = file_get_contents('array.txt', true); 我得到 $printdoc 作为字符串而不是数组
任何帮助?

4

1 回答 1

1

您可以使用 serialize() 将数组转换为可序列化的字符串,然后将其存储在文件中。当您从文件中读取字符串时,使用 unserialze() 将其转换回数组。

于 2013-08-03T17:01:07.433 回答