How do I store an array in a file to access as an array later with PHP?

前端 未结 8 1363
粉色の甜心
粉色の甜心 2020-12-02 14:17

I just want to quickly store an array which I get from a remote API, so that i can mess around with it on a local host.

So:

  1. I currently have an array.<
8条回答
  •  日久生厌
    2020-12-02 14:36

    You can use serialize to make it into a string to write to file, and the accompanying unserialize to return it to an array structure.

    I'd suggest using a language independent structure though, such as JSON. This will allow you to load the files using different languages than PHP, in case there's a chance of that later. json_encode to store it and json_decode($str, true) to return it.

提交回复
热议问题