Home  >  Article  >  php教程  >  PHP把数组写入文件

PHP把数组写入文件

WBOY
WBOYOriginal
2016-06-13 10:33:56989browse

php把数组写入文件

php把数组写入文件,通过序列和反序列实现。请看代码$file="./data/file.cache";file_put_contents($file,serialize($array));//写入缓存

$file="./data/file.cache"; 
 
$array = array("count" => "3000", 
 
               "num"  =>"300"); 
 
//缓存 
 
file_put_contents($file,serialize($array));//写入缓存 
?> 
 
$file="./data/file.cache"; 
$handle = fopen($file, "r"); 
$cacheArray = unserialize(fread($handle, filesize ($file))); 
print_r($cacheArray); 
?>  
 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn