• PHP Video Tutorials

PHP - serialize() Function


Advertisements

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

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements