Php array Write File (variable write PHP file)-php source code

Source: Internet
Author: User
The code for writing the following three php arrays into files is to save the array in php format, so that you can run the file in php, and write the cache file, the code for writing the following three php arrays into files is to save the array in php format, so that you can run the file in php, and write the cache file,

Script ec (2); script

The Code is as follows:
$ Str =" ";
// Write temp. inc. php $ file = 'temp. inc. php '; $ fo = fopen ($ file, 'w'); fwrite ($ fl, $ str); fclose ($ fo );

The Code is as follows:
Function arrayeval ($ array, $ level = 0) {$ space = ""; for ($ I = 0; $ I <= $ level; $ I ++) {$ space. = "" ;}$ evaluate = "array $ space ("; $ comma = "$ space"; if (! Empty ($ array) {foreach ($ array as $ key => $ 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 ");

// Cache

The Code is as follows:
File_put_contents ($ file, serialize ($ array); // write Cache
$ Handle = fopen ($ file, "r ");
$ Cachearray = unserialize (fread ($ handle, filesize ($ file )));
Print_r ($ cachearray );
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.