Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use serialize and unserialize in php

Shulou Source: shulou.com Published: 2022-06-01 18:29:03 09月14日 Update

This article is about how to use serialize and unserialize in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In PHP, the serialize () function is used to serialize objects or arrays, and the unserialize () function is used to deserialize objects or arrays serialized by the serialize () function. The syntax is "serialize (object or array)" and "unserialize (string)".

Operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

What is the use of serialize and unserialize in php

The serialize () function serializes an object or array and returns a string.

After serializing the object, the serialize () function can easily pass it to other places where it is needed, and its type and structure will not change.

If you want to change the serialized string back to the value of PHP, use unserialize ().

The unserialize () function is used to deserialize the object or array serialized by the serialize () function and return the original object structure.

The syntax is as follows:

String serialize (mixed $value) mixed unserialize (string $str)

$value: the object or array to serialize.

Str: the serialized string.

Examples are as follows:

Output result:

ARanger 3: {iRAPR 0 Srig 6: "Google"; iRO 1 Tan Srig 6: "Runoob"; iRO 2 th Srig 8: "Facebook";}

Examples are as follows:

Output result:

Thank you for reading! This is the end of the article on "how to use serialize and unserialize in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Sequences objects functions arrays characters strings content more examples articles structures results syntax output good original practical local tutorials articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology Shulou Information Apple Shulou Tech Info