I’m trying to push a row to my array. I have an array that looks like this:
JavaScript
x
$array = [
[
{ "id": 1, "name": "John" },
// Another object
],
[
{ "id": 1, "name": "Jeff" },
{ "id": 2, "name": "Jane" },
]
];
Advertisement
Answer
JavaScript
$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)