$array = json_decode(file_get_contents('composer.json'), true);
//var_dump($array);die;
function writePhp(array $array)
{
$composer = '';
foreach ($array as $key => $val) {
//判断是否为多维数组
if (is_array($val)) {
//递归处理下一级
$composer .= "'" . $key . "' => [\r\n" . writePhp($val) . "],\r\n";
} else {
//替换目录分隔符以及外单内单双引号
$val = strtr($val, ['\\'=>'\\\\',"'"=>"\\'"]);
$key = strtr($key, ['\\'=>'\\\\',"'"=>"\\'"]);
$composer .= "'" . $key . "' => '" . $val . "',\r\n";
}
}
return $composer;
}