function exportArray($array = [], $indentation = "")
{
$phpCode = "[";
foreach ($array as $key => $value) {
if (is_array($value)) {
$phpCode .= "\n" . $indentation . " " . var_export($key, true) . " => " . $this->exportArray($value, $indentation . " ") . ",";
} else {
$phpCode .= "\n" . $indentation . " " . var_export($key, true) . " => " . var_export($value, true) . ",";
}
}
$phpCode .= "\n" . $indentation . "]";
return $phpCode;
}
$json = '{"name": "John", "age": 30, "city": "New York"}';
$array = json_decode($json, true);
$phpCode = exportArray($array);
file_put_contents(__FILE__ . 'Code.php', $phpCode, FILE_APPEND);
网友评论