NYCPHP Meetup

NYPHP.org

[nycphp-talk] Arrays out of a file and back in?

Tim Lieberman tim_lists at o2group.com
Tue Oct 20 21:42:18 EDT 2009


On Oct 20, 2009, at 6:05 PM, Leam Hall wrote:

> Down the road I'll get this going in a database, but at the moment  
> I'm stuck using flat files to store multi-dimensional array data. So  
> I have a file that gets imported, is used and potentially changed,  
> and then needs to be written back to a file if any data changed.
>
> Is there a good way to do this other than just iterate through each  
> array?

Sounds like a job for json_encode/json_decode.

You could use serialize(), but serialize() can have problems with  
multibyte characters.

json_[de|en]code will create nice, concise, strings.

The advantage of serialize() over the json functions is that serialize  
can serialize objects, and you'll actually get them back (assuming the  
class has been defined when you call unserialize()

-Tim




More information about the talk mailing list