Created
May 27, 2013 12:17
-
-
Save dehart/5656776 to your computer and use it in GitHub Desktop.
Saving a PHP array to a PHP file that returns an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function save($path, $array) | |
{ | |
$data = "<?php\nreturn array("; | |
foreach ($array as $key => $value) { | |
$data .= "'" . $key . "'=>". var_export($value,true).';' . "\n"; | |
} | |
$cdata .= "\n);"; | |
//make sure directory exists before creating | |
return file_put_contents($path, $data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment