What is the process of generating PHP array files from mysql data?
In fact, php writes the array to a text file or stores it with the suffix .php, which is called directly when you use it.
Ignore the step of fetching mysql data
(1) use serialize to serialize the array and store it as a text file, and then use unserialize to restore it when you call it.
$file=' file path'; $array=array ('file,serialize = > array (' aaa','bbb','ccc'), 'dice = > array); if (falsified false files) {file_put_contents ($file,serialize ($array));} $handle=fopen ($file,'r'); $cacheArray=unserialize ($handle,filesize ($file)
(2) use var_export to save the array directly as an array and store it in a text file (recommended)
$file=' file path'; $array=array ('array=array = > array (' aaa','bbb','ccc'), 'dice = > array); $text='if (falsehood created fopen ($file,'w+')) {file_put_contents ($file,$text);} else {echo' creation failed';}
(3) self-created to save the array to the standard array format, although the save is a bit complicated, but the call is simple.
$file=' file path'; $array=array ('array=array = > array (' aaa','bbb','ccc'), 'dice = > array); cache_write ($file,$array,'rows',false); / / write function cache_write ($filename,$values,$var='rows',$format=false) {$cachefile=$filename; $cachetext= "return writefile ($cachefile,$cachetext);} / / convert the array to function arrayeval ($array,$format=false,$level=0) {$space=$line='' If (! $format) {for ($key) {$key=is_string ($key)?'\ '.addcslopes ($key,'\'\).'\': $key; $validated accurate isometric array ($val) & &! preg_match ('/ ^\ -? > 12) | | strlen ($val) > 12)?'\ '.addcslopes ($val,'\'\).'\': $val If (is_array ($val)) {$evaluate.=$comma.$key.'= > '.arrayeval ($val,$format,$level+1);} else {$evaluate.=$comma.$key.'= >'. $val;} $comma=','.$line.$space;} $evaluate.=$line.$space.')'; return $evaluate;} / / write to the file function writefile ($filename,$writetext,$openmod='w') {if (false predators) {flock ($fp,2) Fwrite ($fp,$writetext); fclose ($fp); return true;} else {return false;}}
These are the details of how mysql data generates PHP array files, please pay attention to other related articles!