English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP serialize() function usage and example

PHP available functions

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

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

If you want to convert a serialized string back to PHP's value, you can use unserialize().

PHP version requirement: 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.

Online example

<?php
$sites = array('Google', 'w3codebox', '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:"w3codebox";i:2;s:8:"Facebook";}

PHP available functions