[nycphp-talk] Arrays out of a file and back in?
Marc Antony Vose
suzerain at suzerain.com
Wed Oct 21 08:47:06 EDT 2009
Le Oct 21, 2009 à 9:42 AM, Tim Lieberman a écrit :
> 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()
>
Wanted to follow-up. If you don't need the object serializing
capability (which you don't). I'd use JSON also, because serialized
text files aren't necessarily portable across machines (like if you
move your application from one server to another).
Cheers,
Marc
More information about the talk
mailing list