Use Serialize() to encode variables and their values into a textual form:
$pantry = array('sugar'=>'2 lbs.', 'butter'=' 3 sticks'); $fp = fopen('/tmp/pantry', 'w') or die("Can't open pantry"); fputs($fp, serialize($pantry)); fclose($fp);
To re-create the variables, use unserialize():
$new_pantry = unserialize('file_get_contents('/tmp/pantry')); var_dump($new_pantry);