i have some php arrays saved in a .log file
i want to read them into a php array such as
array[0] = 1st array in the .log file
array1 = 2nd array in the .log file
the solution here does not work for me
it gives no such file or directory error but when i do include_once(‘file.log’) the content in the file is displayed as the output ( i dont know why ) please help
You could
serializethe array before writing it as text to a file. Then, you can read the data back out of the file,unserializewill turn it back into an array.http://php.net/manual/en/function.serialize.php
EDIT Describing the process of using serialize/unserialize:
So you have an array:
When I call
serializeon that array, I get a string:So I want to write that data into a file:
Later, I want to use that array. So, I’ll read the file, then unserialize:
Hope that helps!
EDIT 2 Nesting demo
To store more arrays into this file over time, you have to create a parent array. This array is a container for all the data, so when you want to add another array, you have to unpack the parent, and add your new data to that, then repack the whole thing.
First, get your container set up:
Now, from there forward, when you want to add a new array, first you have to get the whole package out and unserialize it: