我正在尝试使用php symfony2 Yaml包创建yml文件。 我有一个关联数组,如下所示:
$a = Array ( [name] => gfg
[time] => 1440
[vals] => Array ( ['# comment1'] => Array ( [temp] => Array ( [0] => sample [1] => rgr)
['# comment2'] => Array ( [quantity] => 1 ) ) ) ) )
$yaml = Yaml::dump($a, 10, 2);
file_put_contents('../path/sample.yml', $yaml);
正在打印
sample.yml
name: gfg
time: 1440
vals:
-'# comment1':
temp:
-sample
- rgr
- '# comment2':
quantity: 1
预期:
sample.yml
name: gfg
time: 1440
vals:
# comment1
- temp:
-sample
- rgr
# comment2
- quantity: 1
我们可以这样做吗?请建议。