Skip to main content

Store Array in File, read/write Arrays in File.

<?php

// Store PHP Array in File
file_put_contents('array.txt', json_encode($your_array));

// Read Array from File
$your_array = json_decode(file_get_contents('array.txt'), true);

// Serialize()
// --------------------------------------------------------
// Another approach is to use the serialize() and unserialize()
// functions of PHP. You may want to read this to choose between them:
// http://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize
?>