What is the use of the Serialize function? What's the difference with JSON?

Source: Internet
Author: User

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





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.