Storing and Retrieving Arrays in PHP
To store an array for later retrieval with PHP, you have multiple options. One efficient and flexible approach is through JSON serialization. Here's how to do it:
Storing an Array (store_array)
Example:
<code class="php">$arr1 = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5]; file_put_contents("array.json", json_encode($arr1));</code>
Retrieving an Array (restore_array)
Example:
<code class="php">$arr2 = json_decode(file_get_contents('array.json'), true);</code>
The json_encode() and json_decode() functions provide efficient and human-readable serialization of arrays, making it easy to store and retrieve arrays as needed.
The above is the detailed content of How to Store and Retrieve Arrays in PHP Using JSON Serialization?. For more information, please follow other related articles on the PHP Chinese website!