Preferred method to store PHP arrays (json_encode vs serialize)

前端 未结 20 1914
孤独总比滥情好
孤独总比滥情好 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:37

    JSON is simpler and faster than PHP's serialization format and should be used unless:

    • You're storing deeply nested arrays: json_decode(): "This function will return false if the JSON encoded data is deeper than 127 elements."
    • You're storing objects that need to be unserialized as the correct class
    • You're interacting with old PHP versions that don't support json_decode

提交回复
热议问题