PHP Serialize Defination 

 

The serialize function convert any PHP variable value into a string. Basically  serialize is most often used for storage of complex variables for future use. The string can be convert into the original value using unserialize.

 

 

   Serialized string syntax 

 

Example :

 

$myarray = array('name' => 'Arifhossen', 'address' => 'dhaka-bangladesh');
$serialize_string = serialize($myarray);


 
Variable Type Syntax Example - PHP Example - Result
Integer i:<value> serialize(2); i:2;
Decimal / Float d:<value> serialize(2.1); d:2.100000000000000088817841970012523233890533447265625;
String s:<string length>:<value> serialize('one'); s:3:"one";
Array a:<array length>:{<value><value>...} serialize(array('first' => 'one', 'second' => 2)); a:2:{s:5:"first";s:3:"one";s:6:"second";i:2;}
Object O:<type string length>:<property count>:{<property value><property value>...} serialize(new stdClass()); O:8:"stdClass":0:{}

 

 



Tags : php,