html library PHP security

This site requires Flash Player 9 or better.

PHP

Caching an array to disk

I discovered the var_export function in PHP about a year ago. It is able to return a string that represents the passed variable. The returned string is parsable by PHP.

One way to use this function would be to cache an array to a file.

In example:

export.php
<?php
//will write the array to disk
$ar = array('test','testing');
$content = var_export($ar,true);
file_put_contents('cache.php',"<?php\n\$cache=$content;");
?>
 
import.php
<?php
//will output the cached array
include 'cache.php';
var_dump( $cache );

Discussion

One comment for “Caching an array to disk”

Post a comment