I thought it would be simple but of course I'm at a roadblock, I'm new to handling JSON data but here is the info.
$new_item = '[2554560000, 18.26]';
$load = file_get_contents("json/graphlist.json");
$data = json_decode($load, true);
var_dump($data);
echo "<br /><br />";
echo ($data['product1']);
echo "<br /><br />";
echo json_encode($data);
$save = file_put_contents('json/graphlist.json', json_encode($data));
JSON Data:
{"product1":[[243500000,17.85],[245500000,14.65],[248500000,16.22]]}
when I var_dump the decoded data it comes out as:
array(1) { ["product1"]=> array(3) { [0]=> array(2) { [0]=> int(243500000) [1]=> float(17.85) } [1]=> array(2) { [0]=> int(245500000) [1]=> float(14.65) } [2]=> array(2) { [0]=> int(248500000) [1]=> float(16.22) } } }
yet when I echo the product1 array it only shows:
Array
So my question is how do I access the data within the second Array. Then append the data from $new_item to the existing strings to be saved back to the JSON file. I've looked everywhere yet I can't find anyone with similar examples or errors.
echo $data['product1'][0][0];
or view the whole array byprint_r $data['product1'];
– dleiftah 2 days ago