下面的代码解释得更好,我想做什么:
[
[
{
"text":"Row 1 Column 1"
},
// My mine is add anthor JSONObject in here.
],
[
{
"text":"Row 2 Column 1"
},
{
"text":"Row 2 Column 2"
}
]
]
$json= '
[
[
{
"text":"Row 1 Column 1"
}
],
[
{
"text":"Row 2 Column 1"
},
{
"text":"Row 2 Column 2"
}
]
]
';
$p = json_decode($j);
$p[0][]=["text"=>"Row 1 Column 2"];
print_r(json_encode($p)); // print_r for debug, $result = json_encode($p)
我会这样:
$array = [
[
[
"text" => "Row 1 Column 1"
]
],
[
[
"text" => "Row 2 Column 1"
],
[
"text" => "Row 2 Column 2"
]
]
];
// a element in the first sub array
$array[0][] = [
"text" => "Row 1 Column 2"
];
有帮助吗?