I am trying to save multiple php arrays one at a time. The arrays come to me from a parser function also one at a time. I used to keep them all in memory and then write them all at once like this:
while($onearr = parser())
$allarr[] = $onearr;
..
..
fwrite($filename,json_encode($allarr));
But this logic did not hold for long. I started running out of memory quickly. I want to write the arrays one at a time to the same file and read them one at a time too. This is my writer function:
function savearr($onearr) {
if($fp = fopen('arrFile.json','a+')) {
$rc = fwrite($fp, json_encode($onearr));
fclose($fp);
}
}
Now I cannot figure a way to read these arrays! Any way to do it? I tried reading the whole file at once but was not sure how to parse it correctly into individual arrays to match the original!
Thanks in advance