Home > php教程 > php手册 > body text

PHP把数组写入文件

WBOY
Release: 2016-06-13 10:33:56
Original
987 people have browsed it

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); 
?>  
 

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template