K
K
KiselevPD2017-05-30 22:25:18
PHP
KiselevPD, 2017-05-30 22:25:18

How to write to JSON without overwriting?

Good evening. There is a problem when writing to a JSON file:
there is a code

$arrayApi = array('date'=>$datetime[0], 'time'=>$datetime[1], 'price'=>$date[0]['price'], 'discount_price'=>$date[0]['discount_price'], 'is_free'=>$date[0]['is_free']);
    $res = json_encode($arrayApi);
    file_put_contents("1.json",$res);

which writes to a JSON file and at the output we get
{"date":"2017-05-31","time":"02:00:00","price":"4000","discount_price":"3000","is_free":"1"}

Every time you run it, it deletes the previous line, but you need to continue the list until the number of lines reaches 14:
{"date":"2017-05-30","time":"00:00","price":5000,"discount_price":4000,"is_free":false},{"date":"2017-05-30","time":"01:30","price":5000,"discount_price":4000,"is_free":false},{"date":"2017-05-30","time":"03:00","price":5000,"discount_price":4000,"is_free":false}

What needs to be added to achieve the result?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2017-05-30
@KiselevPD

look at the manual?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question