file put contents with array

php

Solution

You want to `serialize()` the array on writting, and `unserialize()` after reading the file.

$array = array('foo' => 'bar');
file_put_contents('foo.txt', serialize($array));
$array = unserialize(file_get_contents('foo.txt')));

Oh, and I really don't now how you echo'd your array, but `echo array('foo' => 'bar');` will always print `Array`.

Problem

I am using `file_put_contents($file, $data);` function for putting contents in file, because these files are created on fly with name of sessions, $data is an multi-dimensional array, when i am echoing array it prints out fine but in file no contents get recorded except the word Array What should i do or is there any other function which automatically creates the file and records the data (array)? Thank You.

Original source