• PHP Video Tutorials

PHP - serialize() Function



Definition and Usage

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.

Syntax

string serialize ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The value to be serialized.

Return Values

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.

Dependencies

PHP 4 and above

Example

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;
?>

Output

This will produce following result −

O:5:"test1":1:{s:11:"test1name";s:14:"TutorialsPoint";}
php_variable_handling_functions.htm
Advertisements