Serialization in PHP:
Serialization is a technique used by programmers to preserve their working data in a format that can later be restored to its previous form.Serializing an object means converting it to a byte stream representation that can be stored in a file.
Serialization in PHP is mostly automatic, it requires little extra work from you, beyond calling the serialize() and unserialize() functions.
Serialize():
The serialize() converts a storable representation of a value.
The serialize() function accepts a single parameter which is the data we want to serialize and returns a serialized string
A serialize data means a sequence of bits so that it can be stored in a file, a memory buffer, or transmitted across a network connection link. It is useful for storing or passing PHP values around without losing their type and structure.
Syntax:
serialize(value);
unserialize():
unserialize() can use string to recreate the original variable values i.e. converts actual data from serialized data.
Syntax:
unserialize(string);
Example:
<?php
$a=array('Shivam','Rahul','Vilas');
$s=serialize($a);
print_r($s);
$s1=unserialize($s);
echo "<br>";
print_r($s1);
?>
Output:a:3:{i:0;s:6:"Shivam";i:1;s:5:"Rahul";i:2;s:5:"Vilas";}
Array ( [0] => Shivam [1] => Rahul [2] => Vilas )
Comments
Post a Comment