Skip to content

Instantly share code, notes, and snippets.

@dehart
Created May 27, 2013 12:17
Show Gist options
  • Save dehart/5656776 to your computer and use it in GitHub Desktop.
Save dehart/5656776 to your computer and use it in GitHub Desktop.
Saving a PHP array to a PHP file that returns an array
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