The function serialize() is used to generate a storable representation of a value. This is useful for storing or passing PHP values around without losing their type and structure.
string serialize ( mixed $value )
Sr.No | Parameter & Description |
---|---|
1 |
value The value to be serialized. |
This function returns a string containing a byte-stream representation of value that can be stored anywhere.
The returned value is a binary string which may include null bytes, and needs to be stored and handled as such. For example, serialize() output should generally be stored in a BLOB field in a database, rather than a CHAR or TEXT field.
PHP 4 and above
Following example demonstrates the serialize() use −
<?php class test1{ private $name; function __construct($arg){ $this->name=$arg; } } $obj1=new test1("TutorialsPoint"); $str=serialize($obj1); echo $str; ?>
This will produce following result −
O:5:"test1":1:{s:11:"test1name";s:14:"TutorialsPoint";}