// 原來的數組
$list = array(
array(
'id' => 1,
'is_open' => 1,
'city' => '上海',
),
array(
'id' => 2,
'city' => '北京'
),
array(
'id' => 3,
'city' => '南京'
),
array(
'id' => 4,
'city' => '蘇州'
),
);
file_put_contents('aa.txt', serialize($list)); // 序列化並寫入文件
$readArray = unserialize(file_get_contents('aa.txt')); // 讀取並反序列化
print_r($readArray);
?>
輸出的結果如下
Array
(
[0] => Array
(
[id] => 1
[is_open] => 1
[city] => 上海
)
[1] => Array
(
[id] => 2
[city] => 北京
)
[2] => Array
(
[id] => 3
[city] => 南京
)
[3] => Array
(
[id] => 4
[city] => 蘇州
)
)
*