php tutorial array write file (variable write php file)
The following three php array write file code, there are two kinds of array is saved in php format, so you can run this file in php, there is a write cache file,
* /
$ str = "<? phprn $ list =". var_export ($ list). "; rn?>";
// write to temp.inc.php $ file = 'temp.inc.php'; $ fo = fopen ($ file, 'w'); fwrite ($ fl, $ str); fclose ($ fo);
function ($ array = $ level = 0) {$ space = ""; for ($ i = 0; $ i <= $ level; $ i ++) {$ space. = "t";} $ evaluate = "arrayn $ space (n); $ comma = "$ space"; if (! empty ($ array)) {foreach ($ array as $ key => $ val) {$ val = empty $ key = is_string ($ val)? "'" .addcslashes ($ key,' ').' '": $ key; if (is_array ($ val)) {$ evaluate. = "$ comma $ key =>" .arrayeval ($ val, $ level + 1);} else {$ evaluate . = "$ comma $ key => $ val";} $ comma = ", n $ space";}} $ evaluate. = "n $ space)"; return $ evaluate;}
$ file = "./ www.jzread.com/file.cache";
$ array = array ("count" => "3000", "num" => "300");
// cache
file_put_contents ($ file, serialize ($ array)); // Write to the cache
$ handle = fopen ($ file, "r");
$ cachearray = unserialize (fread ($ handle, filesize ($ file)));
print_r ($ cachearray);