What is the use of the serialize function? What's the difference with JSON?
Official explanation:
Serialize (PHP3 >= 3.0.5, PHP4) Serialize---produces a value that can be stored in the notation syntax: String serialize (mixed value) Description: Serialize () returns one containing the VA Lue represents the Byte-stream string, which can be stored anywhere. This can be used to store or pass the values of PHP without losing their form and structure. Using Unserialize () allows the serialized string to become the original PHP value again. Serialize () can handle a type that has an integer, double, string, array (multi-faceted), object (the property of the object will be serialized, but the method will be lose)
Attention:
Serialize () can handle any type except resource .
Use Demo:
<?php$a=array (' A ', ' B ', ' C China '), $a =serialize ($a), echo $a. ' <br/> '; $b =unserialize ($a);p rint_r ($b);
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/42/2A/wKioL1PW87ujqDbBAAB5v4RCKco101.jpg "title=" 2014-07-29_090152.png "alt=" Wkiol1pw87ujqdbbaab5v4rckco101.jpg "/>
Personal understanding (Popular speaking), is used to save a variety of forms of things, easy to pass.
What is the difference from JSON?
JSON is a lightweight format for data interchange. Easy for people to read and write. It is also easy for machine parsing and generation. JSON is a better solution for exchanging data in Ajax instead of XML.
$arr = Array (' Name ' = ' Peter ', ' age ' =>20); $jsonencode = Json_encode ($arr); Echo $json Encode
{"Name": "Peter", "Age": 20}
Reference Study Address:
PHP Serialize & JSON parsing
Serialize and unserialize usage in PHP