- // Serialize the array
- $ Test = array ("a" => 0, "B" => 0, "c" => 0 );
- $ Test2 = '';
- $ Test2 = serialize ($ test );
- Echo $ test2;
- Echo "";
- 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:
- Array (
- 'A' => 0, // 0
- 'B' => 0, // 0
- 'C' => 0 // 0 negative ratings
- )
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. |