I'm trying to create a data cache for a SOAP server. How can I store a multidimensional array in a file (unknown dimensions). I understand you can use print_r() to display the contents/heirarchy of an array but how can I store it in a file? I was thinking of something like this : i want to store this variable $x in a php file so that I can just use include(); to load that variable. so i just do something like fwrite($file,'$x = '.$x); then use include($filename); whenever I want to load the variable. that, but I need to do it with multidimensional arrays.
The simplest way of doing this is with PHP's built-in serialize and unserialize functions. serialize will handle all kinds of data types for you, including multidimensional arrays, and create a string representation. However, instead of including it when trying to retrieve data, you'll need to use the unserialize function. Example: // To save data to file fwrite($file, serialize($array)); // To read data back $array = unserialize(fread($file, <length of file>)); PHP:
thanks. That function was actually on my mind though I didn't know what it actually does... now I know. =)