PHP serialize() Function

PHP 可用的函数PHP Available Functions

serialize()This function is used to serialize an object or array and returns a string.

serialize()After the function serializes an object, it can be easily passed to other places that need it, and its type and structure will not change.

If you want to convert the serialized string back to a PHP value, you can useunserialize()。

PHP Version Requirements: PHP 4, PHP 5, PHP 7

Syntax

string serialize ( mixed $value )

Parameter Description:

  • $value: The object or array to be serialized.

Return Value

Returns a string.

Example

Example

<?php $sites = array('Google', 'Example', 'Facebook'); $serialized_data = serialize($sites); echo $serialized_data . PHP_EOL; ?>

The output result is:

a:3:{i:0;s:6:"Google";i:1;s:6:"Example";i:2;s:8:"Facebook";}

PHP 可用的函数PHP Available Functions

Other Extensions