给出以下简单的yaml数据,
$sql = "SELECT * FROM task WHERE date_time_from = '0000-00-00'";
如果我想创建一个完全相同的数据结构的数组,那么正确的方法是什么?
我已经尝试了
foo: 1
bar:
- one
- two
或,
first:
foo: 1
bar:
- one
- two
- three
second:
foo: 2
bar:
- one1
- two2
- three3
还有,
- foo: 1
bar:
- one
- two
- three
- foo: 2
bar:
- one1
- two2
- three3
但似乎没有一个正确的方法。有帮助吗?谢谢!
答案 0 :(得分:3)
我认为你要么在这之后:
- foo: 1
bar:
- one
- two
- three
- foo: 2
bar:
- one1
- two2
- three3
这给你这个结构:
[
{
"foo": 1,
"bar": [
"one",
"two",
"three"
]
},
{
"foo": 2,
"bar": [
"one1",
"two2",
"three3"
]
}
]
或者,如果“第一个”和“第二个”标签对您很重要:
first:
foo: 1
bar:
- one
- two
- three
second:
foo: 2
bar:
- one1
- two2
- three3
它为您提供字典/关联数组:
{
"second": {
"foo": 2,
"bar": [
"one1",
"two2",
"three3"
]
},
"first": {
"foo": 1,
"bar": [
"one",
"two",
"three"
]
}
}