J'ai un tableau de JSON imbriqué dans un fichier qui ressemble à ceci:Append tableau JSON imbriqué avec php
{
"id": 12345679,
"gid": 6012,
"history": [
{
"date": "0000-00-00 00:00:00",
"rank": 6
}
]}
Je suis curieux de voir comment je peux lire le fichier JSON et ajoutez le tableau de l'histoire avec php, puis re -écrire le fichier nommé data.json.
C'est ce que j'ai jusqu'ici.
$json = file_get_contents('data.json');
$json = (array)json_decode($json);
$output = $json['history'][] = array(
array('date' => '0000-00-00 00:00:00', 'rank' => 3),
array('date' => '0000-00-00 00:00:00', 'rank' => 2),
array('date' => '0000-00-00 00:00:00', 'rank' => 6)
);
$data = json_encode(array_marge($json, $output));
Merci pour l'aide!