I have An array which looks like following after using print_r
Array ( [0] => Array ( [0] => piklu [name] => piklu ) [1] => Array ( [0]
Here are two ways:
(1) Write a JSON representation of the array object to the file.
$arr = array( [...] );
file_put_contents( 'data.txt', json_encode( $arr ) );
Then later...
$data = file_get_contents( 'data.txt' );
$arr = json_decode( $data, true );
(2) Write a serialized representation of the array object to the file.
$arr = array( [...] );
file_put_contents( 'data.txt', serialize( $arr ) );
Then later...
$data = file_get_contents( 'data.txt' );
$arr = unserialize( $data );
I prefer JSON method, because it doesn't corrupt as easily as serialize. You can open up the data file and make edits to the contents, and it will encode/decode back without big headaches. Serialized data cannot be changed so easily or corrupted, or unserialize() won't work. Each variable is defined by type and length, and these values must be updated along with the actual change you are making.