PHP unserialize

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : unserialize() function

Description

The unserialize() converts to actual data from serialized data.

Version

(PHP 4 and above)

Syntax

unserialize(string1)

Parameter

Name

Description

Required /
Optional

Type

string1

The serialized string.

Required

String

Return value

Converted value. The value can be a boolean, array, float, integer or string.

Value Type : Mixed*.

*Mixed : Mixed indicates that the return value may multiple (but not necessarily all) types.

Example :

  1. $serialized_data = serialize(array('Math', 'Language', 'Science'));  

  2. echo  $serialized_data . '
    ';  

  3. // Unserialize the data  

  4. $var1 = unserialize($serialized_data);  

  5. // Show the unserialized data;  

  6. var_dump ($var1);  

  7. ?>  

Output :

a:3:{i:0;s:4:"Math";i:1;s:8:"Language";i:2;s:7:"Science";}
array(3) { [0]=> string(4) "Math" [1]=> string(8) "Language" [2]=> string(7) "Science" }