I have a JSON object in a file called info.json that looks like this -->
[
{
"name": "level0",
"items":
[
{
"name": "item1",
"type": "type1"
},
{
"name": "item2",
"type": "type2"
}
]
},
{
"name": "Level1",
"items":
[
{
"name": "item4",
"type": "type4"
},
{
"name": "item5",
"type": "type5"
}
]
},
{
"name": "Level2",
"items":
[
{
"name": "item6",
"type": "type6"
}
]
}
]
and a php script that looks like this -->
<?php
$json_string = file_get_contents("info.json");
$json = json_decode($json_string, true);
array_push($json[0]["items"], array("name" => "item3", "type" => "type3"));
?>
I'm trying to insert a third element in the first instance of "items" in this array, such that when I open the JSON file the new element will appear. What am I doing wrong? Any advice would be appreciated, thanks.