Example of php Serialization array

Source: Internet
Author: User
Example of php Serialization array

  1. // Serialize the array
  2. $ Test = array ("a" => 0, "B" => 0, "c" => 0 );
  3. $ Test2 = '';
  4. $ Test2 = serialize ($ test );
  5. Echo $ test2;
  6. Echo "";
  7. Print_r (unserialize ($ test2 ));

2. PHP Serialization array usage: mainly processing array transfer and array inventory operations.

For example, an array needs to be passed to the next page. if you do not want to use seesion/cookie, you can use the above function for serialization and then restore. For example, if you create a website directory program with a rating, such as praise, moderate rating, and negative rating. Then, the database designs one field for this function, and the type is long standby type. Combine the three comments into an array:

  1. Array (
  2. 'A' => 0, // 0
  3. 'B' => 0, // 0
  4. 'C' => 0 // 0 negative ratings
  5. )

After converting it with the serialize function, it is: a: 3: {s: 1: "a"; I: 0; s: 1: "B"; I: 0; s: 1: "c"; I: 0;}, and then the database exists. Do not forget to use the unserialize function to convert it to an array.

Arrays are often used for serialization. we recommend that you have a strong understanding of them, especially the usage of serialize and unserialize functions.

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.