Preferred method to store PHP arrays (json_encode vs serialize)

前端 未结 20 1897
孤独总比滥情好
孤独总比滥情好 2020-11-22 05:55

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in

20条回答
  •  醉话见心
    2020-11-22 06:32

    Seems like serialize is the one I'm going to use for 2 reasons:

    • Someone pointed out that unserialize is faster than json_decode and a 'read' case sounds more probable than a 'write' case.

    • I've had trouble with json_encode when having strings with invalid UTF-8 characters. When that happens the string ends up being empty causing loss of information.

提交回复
热议问题