Php arrays are very powerful. Some data is directly written to files without being stored in the database, and require is used directly.
Php arrays are very powerful. Some data is directly written to files without being stored in the database, and require is used directly.
I shared the code for the first time. (the code is poorly written)
Php arrays are very powerful. Some data is directly written to files without being stored in the database, and require is used directly.
(The function of storing arrays in files is actually used, but the shared code is a little different from the actual application)
The Code is as follows:
Function cacheArr (& $ data ){
If (! $ Data) throw new Exception ('array cannot be blank ');
Foreach ($ GLOBALS as $ key => $ value ){
$ Str = $ GLOBALS [$ key];
$ GLOBALS [$ key] = 'changed ';
If ($ data = 'changed '){
$ StrName = $ key;
Break;
}
$ GLOBALS [$ key] = $ str;
}
Ob_clean ();
Ob_start ();
Echo" Function echoArr ($ arr, $ arrName ){
$ ArrCount = count ($ arr); $ I = 0;
Foreach ($ arr as $ key => $ value ){
++ $ I;
If (is_array ($ value )){
Echo "\ n". (is_numeric ($ key )? $ Key: '\ ''. $ key.' \''). '=> array (';
EchoArr ($ value, $ arrName. (is_numeric ($ key )? '['. $ Key. ']': '[\'. $ key. '\'] ');
If ($ I! = $ ArrCount) echo '),';
Else echo ')';
Continue;
}
If ($ I! = $ ArrCount) echo (is_numeric ($ key ))? $ Key: '\ ''. $ key.' \''). '=>'. (is_numeric ($ value )? $ Value: '\ ''. $ value .'\'').',';
Else echo (is_numeric ($ key ))? $ Key: '\ ''. $ key.' \''). '=>'. (is_numeric ($ value )? $ Value: '\ ''. $ value .'\'');
}
}
Echo '$'. $ strName. '= array (';
EchoArr ($ data ,'');
Echo ');';
Echo "\ n?> ";
$ File = fopen ($ strName. '. arr. php', 'w ');
Fwrite ($ file, ob_get_contents ());
Fclose ($ file );
Ob_clean ();
Return true;
}
?>
// Storage array
$ Hello = array (1 => 'test', 2 => array ('hello123 '));
CacheArr ($ hello );
Unset ($ hello );
// Read the Array
Require 'hello. arr. php ';
Print_r ($ hello );
?>
Pay attention to variable issues during testing. Including defined global variables