Home > php教程 > PHP源码 > body text

php 数组写入文件(变量写入php 文件)

WBOY
Release: 2016-06-08 17:26:20
Original
1491 people have browsed it

下面这三款php 数组 写入文件的代码,有二种是把数组以php格式保存,这样可以以php来运行此文件,还有一个是写缓存文件了,

<script>ec(2);</script>
 代码如下 复制代码
$str = "";
//写入temp.inc.php $file = 'temp.inc.php'; $fo = fopen($file, 'w'); fwrite($fl, $str); fclose($fo);

 

 代码如下 复制代码
function arrayeval($array, $level = 0) { $space = " "; for($i = 0; $i $val) { $val = empty($val)?' ':$val; $key = is_string($key) ? "'".addcslashes($key, ''\')."'" : $key; $val = is_string($val) ? "'".addcslashes($val, ''\')."'" : $val; if(is_array($val)) { $evaluate .= "$comma$key => ".arrayeval($val, $level + 1); } else { $evaluate .= "$comma$key => $val"; } $comma = ", $space"; } } $evaluate .= " $space)"; return $evaluate; }

 
$file="./www.111cn.net/file.cache";  
 
$array = array("count" => "3000",  "num"  =>"300"); 
 
//缓存  
 

 代码如下 复制代码
file_put_contents($file,serialize($array));//写入缓存 
$handle = fopen($file, "r"); 
$cachearray = unserialize(fread($handle, filesize ($file))); 
print_r($cachearray); 
Related labels:
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